logo

Post-increment vs pre-increment in C (a++ vs ++a)

#include <stdlib.h> #include <stdio.h> int a = 5; int aplusplus() { int temp = a; a = a + 1; return temp; } int plusplusa() { a = a + 1; return a; } int main(int argc, char* argv[]) { // printf("a = %d\n", aplusplus()); // evaluate to 5 // increment a printf("a = %d\n", plusplusa()); // increment a // evaluate to 6 return 0; }
Course thumb

The C programming language made simple