Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operators. The Basics + (addition) - (subtraction) * (multiplication) / (division) % (modulo) ( ) (parentheses)

Similar presentations


Presentation on theme: "Operators. The Basics + (addition) - (subtraction) * (multiplication) / (division) % (modulo) ( ) (parentheses)"— Presentation transcript:

1 Operators

2 The Basics + (addition) - (subtraction) * (multiplication) / (division) % (modulo) ( ) (parentheses)

3 Bitwise operations << (shift left) >> (shift right) | (bitwise or) & (bitwise and) ^ (bitwise exclusive or) ~ (one’s complement)

4 Logical operations || (logical or), && (logical and) ! (logical not) != (not equal), == (equal) (greater than) = (greater than/equal) 0 == false, anything else == true

5 And a few more... ? : (a three way arithmetic if) & (address of), * (dereference) ++ (increment), -- (decrement) -> (dereference),. (member) sizeof() [ ] (array subscript)

6 Order of Precedence ( ) (function call) [ ] (subscripts) -> and. (dereference) sizeof ! ~ - + ++,-- &, * (address,deref) *, /, % +, - >,>= ==,!= & | &&, ||, =

7 Control statements

8 if if (x == 5) x=4; if (x==5) x=0; else x=1; if (x>=5 && x<=10) printf(“Bingo!\n”);

9 for for (i=0;i<10;i++) printf(“%d\n”,i); for(i=0;i<10;i=i+2) for(;;)

10 while while (x != 0) x=x-1;

11 do...while do x=x+1 while (x < 100);

12 More control statements

13 switch char key; scanf(“&c”,&key); switch (key) { case ‘a’: printf(“a is for aardvark\n”); case ‘b’: printf(“b is for beer\n”);break; case ‘c’: printf(“c is for cow\n”);break; default: printf(“Just my ABC’s\n”); }

14 break Necessary for switch statements Can be used in while and for statements “break” out of a loop

15 continue Similar to break but keeps within the loop

16 Printing to the printer The ‘lp’ command lp -d student myprog.c DON’T print a.out lpstat -p cancel student


Download ppt "Operators. The Basics + (addition) - (subtraction) * (multiplication) / (division) % (modulo) ( ) (parentheses)"

Similar presentations


Ads by Google