ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int a = 5;
int b = (a > 3) ? (a = 10) : (a = 20);
printf("%d %d", a, b);- A. 10 10
- B. 20 20
- C. 5 10
- D. 5 5
Correct answer: A. 10 10
The ternary condition (a > 3), i.e. (5 > 3), is true, so ONLY the true branch, (a = 10), executes; the false branch, (a = 20), never runs at all. a is assigned 10, and that assignment expression's value, also 10, becomes b.
More C Programming questions
- What is printed? c int x = 2, y = 3, z = 4; int result = x + y z - x / y; printf("%d", result);
- Assume a 64-bit LP64 ABI. What is printed? c int arr[5] = {1, 2, 3, 4, 5}; int start = arr; int end = arr + 5; int sum = 0; for (int p =…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 42; void vp = &x; int ip = (int )vp; printf("%d", ip);
- Assume a 64-bit LP64 ABI. What is printed? c int a[3] = {1, 2, 3}; int p = &a[1]; printf("%d %d", p[-1], p[1]);
- Assume a 64-bit LP64 ABI. What is printed? c int x = 5; int p = &x; int pp = &p; pp = NULL; printf("%d", p == NULL);
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int q = p; p = NULL; printf("%d %d", p == NULL, q);