notes3

notes3 - What we learned recently ifelse selection...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
if…else selection statements • Ternary conditional operator • Logical Operators while repetition statement • Nested control structures • Reading for this week and next week: • Chap. 4 (skip 4.7)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Assignment operators abbreviate assignment expressions c = c + 3; can be abbreviated as c += 3; Statements of the form variable = variable operator expression can be rewritten as variable operator= expression Examples of other assignment operators: d -= 4 ( d = d – 4 ) e *= 2 ( e = e * 2 ) f /= 3 ( f = f / 3 ) g %= 7 ( g = g % 7 )
Background image of page 2
Fig. 3.11 in book: Assume: int c = 3, d = 5, e = 4, f = 6, g = 12; Assignment operator Sample expression Explanation Assigns += c += 7 c = c + 7 10 to c -= d -= 4 d = d - 4 1 to d *= e *= 5 e = e * 5 20 to e /= f /= 3 f = f / 3 2 to f %= g %= 9 g = g % 9 3 to g
Background image of page 3

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

View Full DocumentRight Arrow Icon
Increment operator ( ++ ) – Can be used instead of c += 1 Decrement operator ( –– ) – Can be used instead of c –= 1 Pre-increment – Operator is used before the variable ( ++c or ––c ) – Variable is changed before the expression containing it is evaluated Post-increment – Operator is used after the variable ( c++ or c–– ) – Variable is changed after the expression containing it is evaluated
Background image of page 4
Fig. 3.12 in book: Assignment operator Sample expressions Explanation Increment a by 1, then use the new value of a in the ++a expression in which a resides. Use the current value of a in the expression in which a Decrement b by 1, then use the new value of b in the Use the current value of b in the expression in which b a++ resides, then increment a by 1. --b expression in which b resides. b-- resides, then decrement b by 1. -- ++ Also see Fig. 3.14 in book for a complete list of operators encountered in Chapters 1 – 3.
Background image of page 5

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

View Full DocumentRight Arrow Icon
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /* pre-incrementing and post-incrementing */ #include <stdio.h> int main() { int c, d; /* declare variables */ /* demonstrate pre-incrementing */ c = 5; /* assign 5 to c */ printf( "\n%d\n", c ); /* print c */ printf( "%d\n", ++c ); /* increment c, then print c */ printf( "%d\n\n", c ); /* print c */ /* demonstrate post-incrementing */
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/02/2009 for the course ENGR 3 taught by Professor Ben-yaakov during the Fall '08 term at UCSB.

Page1 / 28

notes3 - What we learned recently ifelse selection...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online