ProgrammingModerateTCS NQT · C
What is printed?
What is printed?
int a = 3, b = 4;
printf("%d", a < b ? a > 1 ? 10 : 20 : 30);- A. 20
- B. 30
- C. 10
- D. Compile error
Correct answer: C. 10
a < b is true, so the inner conditional is evaluated; a > 1 is true, giving 10.
More C Programming questions
- What is printed? Assume a 4-byte int. c int m[3][4]; printf("%zu %zu %zu", sizeof(m[0]), sizeof(m), sizeof m);
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int p = &a[0][0]; printf("%d %d %d", (p + 4), (a[1] + 2), (a)[2]);
- What is printed? c int i, j; for (i = 0, j = 5; i < j; i++, j--) ; printf("%d %d", i, j);
- What is printed? c int a = 0, b = 0, c; c = (a++ && b++) || (++a || b++); printf("%d %d %d", a, b, c);
- What is printed? c int a = -1; unsigned int b = 1; printf("%d %d", a < b, a < (int)b);
- What is printed? c int f(int n) { return n <= 1 ? 1 : f(n - 1) + f(n - 2) + n; } int main(void) { printf("%d", f(5)); return 0; }