Operators
The Basics + (addition) - (subtraction) * (multiplication) / (division) % (modulo) ( ) (parentheses)
Bitwise operations << (shift left) >> (shift right) | (bitwise or) & (bitwise and) ^ (bitwise exclusive or) ~ (one’s complement)
Logical operations || (logical or), && (logical and) ! (logical not) != (not equal), == (equal) (greater than) = (greater than/equal) 0 == false, anything else == true
And a few more... ? : (a three way arithmetic if) & (address of), * (dereference) ++ (increment), -- (decrement) -> (dereference),. (member) sizeof() [ ] (array subscript)
Order of Precedence ( ) (function call) [ ] (subscripts) -> and. (dereference) sizeof ! ~ ,-- &, * (address,deref) *, /, % +, - >,>= ==,!= & | &&, ||, =
Control statements
if if (x == 5) x=4; if (x==5) x=0; else x=1; if (x>=5 && x<=10) printf(“Bingo!\n”);
for for (i=0;i<10;i++) printf(“%d\n”,i); for(i=0;i<10;i=i+2) for(;;)
while while (x != 0) x=x-1;
do...while do x=x+1 while (x < 100);
More control statements
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”); }
break Necessary for switch statements Can be used in while and for statements “break” out of a loop
continue Similar to break but keeps within the loop
Printing to the printer The ‘lp’ command lp -d student myprog.c DON’T print a.out lpstat -p cancel student