Advertisement
fouzimedfouni

Increasment & Decreasment Operators

Jan 5th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. main()
  3. {
  4.   int x,y,z,a,b,c,e,f,g;
  5.   x=1;
  6.   y=3;
  7.   x = y++;
  8.   printf("#1- %d\n",x); /* in the example #1 the value of -x- will stay the same as -y- cause the increasment did not happened yet */
  9.  
  10.   a=1;
  11.   b=3;
  12.   c = ++b;
  13.   printf("#2- %d\n",c); /* in the example #2 the value of -c- will increase, cause the value is already been added to the value of  -b- */
  14.  
  15.  
  16.   f=9;
  17.   g=10;
  18.   e = f++ + ++g ; /*here we know that the increasment did not happened yet in the value of -f- (still 9),
  19.                      but the increasment of the value of -g- is already increased(from 10 to 11) */
  20.   printf("#3- %d\n",e);
  21.    
  22.    
  23.    
  24.   getchar();
  25.    
  26.     /* you can do the same thing with the Minus (--). The same thing will happened ex: --a and a--*/
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement