ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
int a = 2, b = 4;
printf("%d %d %d", a & b, a && b, a | b);- A. 0 1 1
- B. 0 1 6
- C. 1 1 6
- D. 2 4 6
Correct answer: B. 0 1 6
2 = 010 and 4 = 100 share no bits, so a & b = 0, while a && b treats both as true and gives 1. a | b = 110 = 6. Confusing & with && is the trap in the first two.
More C Programming questions
- What is printed? c int z(int n) { return n < 5 ? 0 : n / 5 + z(n / 5); } int main(void) { printf("%d %d", z(100), z(125)); }
- What is printed? c int next(void) { static int n; return n += 2; } int prev(void) { static int n = 10; return n -= 3; } int main(void) {…
- What is printed? c void rev(char a, char b) { while (a < b) { char t = a; a++ = b; b-- = t; } } int main(void) { char s[] = "abc de"…
- What is printed? c int n = 0; int t(void) { n++; return 1; } int f(void) { n++; return 0; } int main(void) { int r = f() || t() && f() ||…
- What is printed? c int a[] = {3, 5, 0, 7}, i = 0, s = 0, v; while ((v = a[i++])) s += v; printf("%d %d", s, i);
- What is printed? c int cnt[26] = {0}; for (const char p = "banana"; p; p++) cnt[p - 'a']++; int best = 0; for (int i = 1; i < 26; i++) if…