Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Announcements
Lab 11 starts from Friday, 28th October. Thursday section will do lab on 29th October (Saturday) y ( y) Lab exam in the week of 14th to 18th November Labs 11 and 12 will not be pre-announced to give you practice End-sem exam is on 25th November, 8:00 AM t afternoon. Copies can be seen on 28th afternoon
Lec-32
Recap
Command line arguments
main ( ) function has arguments int agrc, char * argv[ ] argc refers to number of arguments argv points on all those arguments
Switch statement
needed when there are multiple else if clauses based on different values of same expression diff t l f i use of case and default keywords use of break
Lec-32
Lec-32
When x is a, all of 0, 1 and 2 are printed When x is b, both 1 and 2 are printed When x is neither, only 2 is printed
Lec-32 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 6
case a: case b: case z: nletter [ c a]++; break; case A: case B: case Z: nletter [ c A]++; break; Z: A ]++; }
Lec-32
Typecasting
We have seen so far
implicit type casting
int i; float f; i = f;
Lec-32
10
Typecasting
Explicit type casting can be used anywhere
int i; int j; float f; f = i / j; // will result in integer division f = (float) i / (float) j ; // will result in floating point division
Lec-32
11
Typecasting
int i; short s; s = 300; i=s*s; i = (int) (s * s) ; i = (int) s * s; (i t) // will result in overflow // will still result in overflow // by force converting first instance of s b f ti fi t i t f // system will convert second one also, and // the result will also be stored in an int
Lec-32
12
Lec-32
13
unsigned type
We can tell system that we will only store non negative non-negative numbers by attaching keyword unsigned to declaration Example:
unsigned short int unsigned int unsigned long int s; i; l;
Lec-32
14
Conditional Operator
Requires three operands:
condition ? expression_1 : expression_2
Meaning:
If condition is true then evaluate (and set value of) expression 1 If condition is false then evaluate (and set value of) expression 2
Example:
int z, a, b; z = (a > b) ? a : b
Lec-32
Conditional Operator
z = (a > b) ? a : b
Lec-32
16
Any Questions?
Lec-32
17