ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int a = 0;
for (int i = 0; i < 4; i++) {
a |= (1 << i);
}
printf("%d", a);- A. 8
- B. 16
- C. 4
- D. 15
Correct answer: D. 15
The loop sets bits 0,1,2,3 one at a time: after all 4 iterations a = 0b1111 = 15.
More C Programming questions
- What is printed? c int x = 255; unsigned char y = (unsigned char)(x << 1); printf("%d", y);
- What is printed? c int x = 5, y = 9; int max = y ^ ((x ^ y) & -(x < y)); printf("%d", max);
- What is printed? c int x = 101; int y = (x >> 2) << 2; printf("%d", y);
- What is printed? c #include <stdio.h> int main(void) { int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = a; printf("%d %d", ((p + 1))[2]…
- Assume a 64-bit ABI with 4-byte int. What is printed? c #include <stdio.h> int main(void) { int a[4]; int p = a; char cp = (char )a…
- What is printed? c #include <stdio.h> int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int main(void) { int…