Write about ++m and m ++ operators.

The  operator ++ adds 1 to the operand.

++m, or m++,

++ m; is equivalent to m=m+1;(m+=1)

We use the increment statements in for and while loops extensively. While ++m and m++ mean the same thing when they form statements independently, they behave differently when they are used in expressions on the right hand side of an assignment statement. Consider the following :

m=5;

y=++m;

in this case the value of y and m would be 6; suppose if we rewrite the above statements as

m=5;

y=m++;

then the value of y would be 5 and m would be 6. A prefix operator first adds 1 to the operand and then the result is assigned to the variable on left. On the other hand, a postfix operator first assigned the value to the variable on left and then increments the operaned.

Leave a comment