02 02 Operators Assignment Arithmetic
02 02 Operators Assignment Arithmetic
Procedural Programming 2
Please see this material first
Procedural Programming 3
Outlines
1. PEMVIS’ “Operators”.
2. Operator.
3. Assignment operator.
4. Arithmetic operators.
5. Prefix and postfix increment and
decrement operations.
Procedural Programming 4
Operator
Procedural Programming 5
Operator
Procedural Programming 7
Assignment operator
identifier = expression;
identifier1 = identifier2 = identifiern = expression;
Procedural Programming 8
Arithmetic Operators
Procedural Programming 9
Arithmetic operators
Procedural Programming 10
Pre- and -post increment and decrement
short int r, s;
r = 0;
• Unary, one operand operator.
s = 1; • They affect the operands
r = ++s; //pre-increment; r:2; s:2; differently.
r = s++; //post-increment; r:2; s:3; • prefix increment/decrement
r = --s; //pre-decrement; r:2; s:2; will operate the operand first.
r = s--; //post-decrement; r:2; s:1;
• postfix increment/decrement
r = ++s + s; //r:4; s:2; will operate the operand after
r = s++ + s; //r:5; s:3; what? (later).
r = s++ + s++; //r:7; s:5; what?
r = s++ + ++s; //r:12; s:7; what?
r = ++s + s++ + s++; //r:25; s:10; what?
Procedural Programming 11
prefix and postfix
short int r, s; increment and decrement
r = 0;
s = 1; Increment first r = (s += 1) + s;
followed by anaddition
r = ++s + s; r = s + (s += 1);
2 2 Addition first followed
by an increment
r = s++ + s; r = s + (s += 1); s += 1;
2 3
Increment first followed by an
addition, then another increment
r = s++ + s++; 5
3 4
Procedural Programming 12
Todos
Procedural Programming 13
References
Procedural Programming 14
Thank
you
Procedural Programming 15