Module 6 Flashcards
(45 cards)
___________ and ___________ operators are special operators which are unique to C and C++
Increment and decrement
The effect of these is to increase or decrease the value of the variable by 1.
Increment and decrement
The ________________ is denoted by ++ (now you
can guess why the updated version of C was called C++
increment operator
The ________________ is denoted by –
decrement operator
i++; ( the ________ form )
postfix
++i; ( the ________ form )
prefix
both of i++ and ++i which are equivalent to
__________ or they can be part of an expression.
i = i + 1;
The __________ version will use the old (not incremented) value in the expression, then once the expression has
ended (shown by a semicolon) only then is the value incremented.
postfix
The ___________ form increments the value straight
away, so the new value is used.
prefix
So if you set i = 10; and then print out its value, the expression
cout «_space;_________ «endl;
will print out the value of 10. Once this expression is finished (once the endl; has been executed) then i is
incremented to give the new value of 11.
i++
On the other hand, if you used cout «_space;________ «endl; then the first thing that happens is that i gets incremented, so
the value printed out is 11.
++i
// increment straight away
++i
// increment, but use old value if i++ is part of
an existing expression
i++
// decrement straight away
–i
// decrement, but use old value if i– is part of
an existing expression
i–
_________ have as objective to repeat a statement a certain number of times or while a condition is fulfilled.
Loops
its function is simply to repeat statement while expression is true.
while loop
The while loop format is:
while (expression) statement
When the program starts the user is prompted to insert a starting number for the countdown. Then the _______ loop begins, if the value entered by the user fulfills the condition, the block of instructions that follows will execute an indefinite number of times while the condition remains true.
while
The do-while loop format is:
do statement while (condition);
The __________ loop performs the statements first and then tests the condition. This means that the body of the loop is always executed at least once.
do…while
The _________ loop performs the conditional test first and then executes the loop, so the statements within a loop may never be executed.
while
The general form of a do…while loop is
do
{
statements;
}while(test_condition);
There is a ___________ at the end of the while condition statement.
This terminates the whole statement and results in one more _______ than the equivalent while loop.
semi-colon