ENGE_2314_EXAM_2__REVIEW

# ENGE_2314_EXAM_2__REVIEW - INCREMENT/DECREMENT OPERATORS...

This preview shows pages 1–3. Sign up to view the full content.

1 ENGE 2314 EXAM 2 REVIEW Spring 2006 INCREMENT/DECREMENT OPERATORS, POSTFIX/PREFIX • Pages 126-128 in the text • Module 5 • The statements x++; ++x; both mean "increment the integer variable x by 1" and the results will be the same after either statement is executed. • Obviously the decrement operator works similarly but decrements by 1 INCREMENT/DECREMENT OPERATORS, POSTFIX/PREFIX • The statements: y = x++; y = ++x; do not result in the same thing. In the first case, y would be set to x and THEN x would be incremented so after the statement y would be one less than x. In the second case x would be incremented and THEN y would be set to x so x and y would have the same value afterwards • The decrement operator works similarly INCREMENT/DECREMENT OPERATORS, POSTFIX/PREFIX • "You should avoid using the increment and decrement operators in complex expressions in which the variables to which they are applied appear more than once." (text) The results are unpredictable and system/compiler dependent • y =i * x + ++i; // unpredictable • j = ++j; // unpredictable

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Compound Assignment Operators • Page 126-128 in text • += , -= , *= , /= , %= • x *= y is same as x = x * y • when working with expressions such as t = t * x + 1 (multiplication before addition) you should realize that there is an implied set of parentheses around the expression on the right when you use a compound assignment operator so t *= x + 1 is evaluated as t *= (x + 1) which evaluates to t = t * (x + 1) [multiplication AFTER addition] not t = t * x + 1 Nested Loops • The inner loop completes all of its repetitions for each repetition of the outer loop for (int k = 0; k < 5; k++) for (int j = 0; j < k; ++j) cout << k << " "<< j << endl;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

ENGE_2314_EXAM_2__REVIEW - INCREMENT/DECREMENT OPERATORS...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online