08. Pre-increment & post-increment MCQ

pre/post Question 1

int x = 4, y, z;
y = --x;
z = x--;
printf("%d, %d, %d\n", x, y, z);
Solution
x = 4;
y = --x; => y = 3 & x = 3;
z = x--; => z = 3 & x = 2;

OUTPUT:
  2, 3, 3

pre/post Question 2

int a = 1, b = 3;
b = a++ + a++ + a++ + a++ + a++;
printf("a = %d \nb = %d", a, b);
Solution
a = 1, b = 3;
b = a++(1) + a++(2) + a++(3) + a++(4) + a++(5); => b = 15 & a = 6

OUTPUT:
  a = 6
  b = 15

pre/post Question 3

int a = 9, b = 9;
a = b++;
b = a++;
b = ++b;

printf("%d %d", a, b);
Solution

pre/post Question 4

Solution

Last updated