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)); }- A. 23
- B. Compilation error: f expects 2 arguments, not 3
- C. 123
- 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
- What is printed? c int x = 0; if (x == 1); x += 5; printf("%d", x);
- What is printed? c int inc(int x) { return x + 1; } int dec(int x) { return x - 1; } int (pick(int c))(int) { return c ? inc : dec; } int…
- What is printed? c #include <limits.h> printf("%u %d", UINTMAX + 1u, UINTMAX == -1);
- What is printed? c int ways(int a, int n, int t) { if (t == 0) return 1; if (n == 0 || t < 0) return 0; return ways(a + 1, n - 1, t…
- What value does this call to printf return? c printf("%5.1f|%-5d|", 3.14159, 42);
- What is printed? c const char w[] = {"red", "green", "blue", "cyan"}; const char p[] = {w + 2, w, w + 3, w + 1}; const char q = p…