ProgrammingHardProduct company OA

What is printed?

What is printed?
int f(int a, int b) { return a * 10 + b; }
int main(void) { printf("%d", f((1, 2), 3)); }
  1. A. 23
  2. B. Compilation error: f expects 2 arguments, not 3
  3. C. 123
  4. D. 13

Correct answer: A. 23

The extra parentheses make (1, 2) a single argument that uses the comma operator, whose value is its right operand, 2. So f receives 2 and 3 and returns 23. Without them, f(1, 2, 3) really would be an error.

More C Programming questions

Exams that ask this topic