ProgrammingHardWipro · Cognizant pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int a = 6;
int b = a++ * 2;
printf("%d %d", a, b);
  1. A. 7 14
  2. B. 7 12
  3. C. 6 12
  4. D. 6 14

Correct answer: B. 7 12

a++ (postfix) yields a's CURRENT value, 6, for use in the multiplication (6*2=12), and only afterward increments a to 7. Since there is exactly one side effect on a within this expression (not two unsequenced ones), this is fully well-defined: a=7, b=12.

More C Programming questions

Exams that ask this topic