| Mathematical expressions | Expressed in the C | Process |
|---|---|---|
| . X or nothing | * | multiplication |
| Mode | % | Modular quotient |
| / | / | Quotient |
| +1 | ++ | Unary increment |
| -1 | -- | Unary decrement |
| + | + | Sum |
| - | - | Difference |
The expression of meaning may change for operator location. The right or left is important.
| header | header |
|---|---|
| A++ (postincrement) | Firstly use A, than add 1 to the number. |
| ++A ( preincrement ) | Firstly add 1 to the A, after use number. |
| A -- ( postdecrement ) | Firstly use A, than subtract 1 to the number. |
| -- A ( predecrement ) | Firstly subtract 1 to the A, after use number. |
An example of a difference in meaning of change unory operator location; For example, should it be : a=4, b=5
| header | header | header | header | header | header |
|---|---|---|---|---|---|
| c=a++ *b | c=a*b a=a+1 | c=4*5=20 a=4+1=5 | a=5 | b=5 | c=20 |
| c=++a–b | a=a+1 c=a - b | a=4+1=5 c=5 - 5=0 | a=5 | b=5 | c=0 |
| c= -- a + b -- | a=a+1 c=a+b b=b - 1 | a=4
-
1=3 c=3+5=8 b=5 - 1=4 | a=3 | b=4 | c=8 |
/* source : freelearncprogramming.blogspot.com */
#include <stdio.h>
main ()
{
int a,b,c;
float c1;
a=4;
b=5;
c=a++*b ;
c1=++a-b ;
printf ("c = %d \n",c);
printf ("c1 = %d \n",c1);
return 0;
}

No comments:
Post a Comment