Multiple choice

What is the output of the following C++ code?

#include <stdio.h> int main() {
int a,b;
a = (b=2,b+3);
printf(%d,a);
return 0; }

  1. 2

  2. Garbage value

  3. 5

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When expressions are seperated by comma operator, they are evaluated from left and the rightmost expressions only used for assignment. Hence, 5 is assigned to a and 5 is printed on the screen. This is the correct answer.