1 / 16

Operators

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.

tobias
Télécharger la présentation

Operators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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) • < (less than), > (greater than) • <= (less than/equal), >= (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. ( ) (function call) [ ] (subscripts) -> and . (dereference) sizeof ! ~ - + ++,-- &, * (address,deref) *, /, % +, - <<, >> <,<=,>,>= ==,!= & | &&, ||, = Order of Precedence

  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

More Related