Post and Pre Increment
When ++ is set at the beginning of a variable it is called prefix increment. i.e: ++x
When ++ is set at the end of a variable it is called postfix increment. i.e: x++
x++ and ++x are equivalent to x=x+1 but what is the difference between x++ and ++x?
x++ will increment the value of x by one but return the previous value.
#include<stdio.h> int main() { int x=65; printf("x++ = %d",++x); return 0; }
OUTPUT
x++ = 65
++x will increment the value of x by one and return the update value.
#include<stdio.h> int main() { int x=65; printf("++x = %d",x++); return 0; }
OUTPUT
++x = 66
Next Previous