ProgrammingHardTCS NQT · Product company OA
What is printed?
What is printed?
int a = 1;
printf("%d %d", a << 2 + 1, (a << 2) + 1 > 4 == 1);- A. 8 1
- B. 5 1
- C. 8 0
- D. 5 0
Correct answer: A. 8 1
+ binds tighter than <<, so a << 2 + 1 is 1 << 3 = 8, not (1 << 2) + 1 = 5. In the second expression the parentheses give 5; > binds tighter than ==, so (5 > 4) == 1 is 1 == 1, which is 1.
More C Programming questions
- What is printed? c int a[] = {4, 7, 4, 9, 7, 9, 9}; int x = 0; for (int i = 0; i < 7; i++) x ^= a[i]; printf("%d", x);
- What is printed? c int a[] = {1, 2, 4, 5, 6}, x = 0; for (int i = 1; i <= 6; i++) x ^= i; for (int i = 0; i < 5; i++) x ^= a[i]…
- What is printed? c int parse(const char s) { int sign = 1, n = 0; if (s == '-') { sign = -1; s++; } while (s >= '0' && s <= '9') n = n 10…
- What is printed? c int a[] = {1, 1, 2, 3, 3, 3, 4}, k = 1; for (int i = 1; i < 7; i++) if (a[i] != a[k - 1]) a[k++] = a[i]; printf("%d…
- What is printed? c int a[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; int best = a[0], cur = a[0]; for (int i = 1; i < 9; i++) { cur = cur + a[i]…
- What is printed? c int a[] = {2, 4, 6, 8, 10, 12, 14}, lo = 0, hi = 6, steps = 0, x = 7; while (lo <= hi) { int m = (lo + hi) / 2…