ProgrammingHardAccenture · Product company OA
What is printed?
What is printed?
int a = 3, b = 0;
int r = (a > b) + (a && b) * 2 + (a || b) * 4 + !b * 8;
printf("%d", r);- A. 5
- B. 15
- C. 13
- D. 14
Correct answer: C. 13
Relational and logical operators give exactly 0 or 1: a > b is 1, a && b is 0, a || b is 1, !b is 1. So r = 1 + 0 + 4 + 8 = 13. '15' assumes a && b is true because a is.
More C Programming questions
- What is printed? c int a[] = {5, 1, 4, 2, 3}; int lo = a, hi = a + 4; while (lo < hi) { if (lo > hi) lo++; else hi--; } printf("%td %d"…
- What is printed? c long memo[50]; int calls = 0; long f(int n) { calls++; if (n < 2) return n; if (memo[n]) return memo[n]; return memo[n]…
- With 4-byte int, what is printed? c int x = 7; printf("%zu %zu", sizeof (int) 3, sizeof x + 1);
- What is printed? c char s[8] = {'a', 'b'}; printf("%zu %zu %d", strlen(s), sizeof s, s[7]);
- What does r(3) print, and how many digits would r(6) print? c void r(int n) { if (n == 0) return; r(n - 1); printf("%d", n); r(n - 1); }
- What is printed? c const char s = "abcdefgh"; const char p = s + 2, q = strchr(s, 'g'); printf("%td %c %s", q - p, (p + (q - p) / 2), q);