What is the difference between ++i and i++ in C?
#include <stdio.h>
int main(void) {
int a = 5, b = 5;
printf("%d\n", ++a); // increase first, then use
printf("%d\n", b++); // use first, then increase
printf("%d %d\n", a, b);
return 0;
}
Output:
Output of the above program is
6
5
6 6
Both end with the value 6. The difference is only in the value of the expression. In a simple loop like for (i = 0; i < n; i++) there is no difference.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |