ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
int a = (1, 2, 3);
int b = 5;
b = (b + 1, b * 2);
printf("%d %d", a, b);- A. 1 10
- B. 3 6
- C. 3 10
- D. 1 6
Correct answer: C. 3 10
The comma operator evaluates its left operand, discards it, and yields the right operand: (1, 2, 3) is 3 and (b + 1, b * 2) is 10. b + 1 does not modify b. Without the parentheses, int a = 1, 2, 3; would not compile.
More C Programming questions
- What is printed? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 2); } } int main(void) { f(3); }
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d %d", ((a + 1) + 2), (a[1] + 1), a + 1);
- What is printed? c char s[] = "hello"; char p = s; printf("%zu %zu %zu", strlen(s), sizeof(s), sizeof(p)); / 64-bit system /
- What is printed? c int i = 10, c = 0; do { c++; i++; } while (i < 5); printf("%d %d", i, c);
- What is printed? c int i, j, s = 0; for (i = 0, j = 10; i < j; i += 2, j--) s += j - i; printf("%d %d %d", i, j, s);
- What is printed? c unsigned int u = -16; / 32-bit unsigned int / printf("%d %u %d", 1 << 4, u >> 28, -16 / 4);