CC++:从基础语法到优化策略 (3).pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《CC++:从基础语法到优化策略 (3).pdf》由会员分享,可在线阅读,更多相关《CC++:从基础语法到优化策略 (3).pdf(36页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、C/C+Program DesignCS205Week 3Some operatorsThe slides are based on the book Increment/Decrement Operators Prefixing versus postfixing:+x,x+,-x,x-Prefix form is more efficient The increment/decrement operators and pointersAdding an increment operator to a pointer increases its value by the number of
2、bytes in the type it points toThe prefix increment,prefix decrement,and dereferencing operators have the same precedence(from right to left)Postfix increment and decrement operators have the same precedence,which is higher than the prefix precedence(from left to right)See program example plus_one.cp
3、p The increment(+)and decrement(-)operatorsCombination assignment operators Combination assignment operators See program example combination.cppThe?:Operator Conditional operator(question mark)See program example conditional.cppfor loopThe slides are based on the book for Loops Why needs loop operat
4、ions?Perform repetitive tasks Most tasks have the same process See program example forloop.cpp Increment operator:+operator(i=i+1;)Introducing for Loops Parts of a for Loop Setting a value initially Testing whether the loop should continue Executing the loop actions-body Updating value(s)used for th
5、e testfor(initialization;test-expression;update-expression)body;Introducing for Loops See program example num_test.cpp Decrement operator:-operator(i=i-1;)The range-based for loop(C+11)See Program example cxx11loop.cppColon symbol:&symbol:reference variableTo modify the array contentsMore Examples S
6、ee program example formore.cpp Factorial definitionZero factorial,written as 0!,is defined to be 1(exclamation marks!)The factorial of each integer being the product of that integer with the preceding factorial See program example bigstep.cpp Changing the step sizeExample:Nested Loops(嵌套)and Two-Dim
7、ensional Arrays Example:int maxtemps45;See program example nested.cppRelational ExpressionsThe slides are based on the book Expressions A C+expression is a value or a combination of values and operators Every C+expression has a value A for control section uses three expressions Relational expression
8、s such as x y evaluate to the bool values Evaluating the expression is the primary effectprimary effectEvaluating x+15 calculates a new value,but it doesnt change the value of xBut evaluating+x+15 does have a side effect because it involves incrementing xRelational Expressions C+provides six relatio
9、nal operators to compare numbers Exclamation markComparisons in Test Expression Program example equal.cpp A mistake youll probably make=or=Program example compstr1.cpp Comparing C-style strings strcmp(str1,str2)Program example compstr2.cpp Comparing string class strings Using relational symbol(!=)wh
10、ile loopThe slides are based on the book The while Loop while is entry-condition loop It has just a test condition and a body Do something to affect the test-condition expression See Program example while.cpp Two types of condition expressionwhile(namei!=0)while(namei)for Versus while In C+the for a
11、nd while loops are essentially equivalentMore Loops The do while Loop Its an exit-condition loop Such a loop always executes at least once See Program example dowhile.cppExample:Loops and Text Input Using unadorned cin for input When to stop?A sentinel character See program example textin1.cppThe pr
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CC+:从基础语法到优化策略 3 CC 基础 语法 优化 策略
![提示](https://www.deliwenku.com/images/bang_tan.gif)
限制150内