Learn about C Program to find Difference between ++i and i++ in the below code example.
Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C Program to find Difference between ++i and i++
These are mainly defined as Post-Increment (i++)and Pre-Increment(++i). Pre-Increment is first incremented and used in expression whereas Post-increment is used in expression and is incremented.
#include<stdio.h>
int main()
{
int a=10,b=20,c,d;
c=a++;//Post-increment and hence 10 is assigned to c and incremented
d=++b;//Pre-increment and hence first increment 21 and assigns to d
printf("a:%d b:%d c:%d d:%d ",a,b,c,d);
return 0;
}
a:11 b:21 c:10 d:21
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Also Read: