Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Announcements
Monday lab scheduled on 15th August will instead be held on Saturday, 20th August. Monday lab scheduled on 22nd August will instead be held on Saturday, 27th August. Wednesday lab scheduled on 31st August will instead be held on Saturday, 3rd September.
Lec-10
Recap
Getting out of loops
break continue
Lec-10
Lec-10
Lec-10
Lec-10
Lec-10
scanf requires Enter before it can read Typed characters are remembered as input.
Lec-10 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 7
scanf requires Enter before it can read Typed characters are remembered as input.
Lec-10 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 8
Arithmetic operators
+ and can be used with character variables Best to avoid multiplication, division and modulus a + 2 will become c z 2 will become x A + 1 = 65 + 49 = 114 = r (avoid) 1 * 2 = 49 * 2 = 98 = b (avoid) ( )
Lec-10
Relational operators
All relational operators are valid with characters
a > b is false (and can be assumed in all environments) The following happened to be true in our lab and on most computers, but dont assume these, in general
a == 97 a > A 5 > 5 5
Lec-10
10
Boolean
Integers are treated as booleans p Value 0 represents false Any non-zero (or is it non-negative?) value is true Example:
(3> 5) will be printed as 0 (3 < 5) will be printed as 1
Lec-10
Unary operators
+ (unary plus) - (unary minus) ++ (increment by one) -- (decrement by one) = (assignment Unary operators associativity is right-to-left Post-increment (i++) Pre-increment (++i) First four unary operators have highest precedence amongst all operators. Assignment operator has lowest precedence
Lec-10 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 12
i = 72; j = --i;
j and i become 71.
c = u; ++c; u ; c;
c becomes v
x = y = 45
Both x and y become 45.
Lec-10 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 13
Lec-10
14
Lec-10
16
Lec-10
17
Any Questions?
Lec-10
18
10