ProgrammingHardProduct company OA
What is printed?
What is printed?
enum { R = 4, W = 2, X = 1 };
int perm = R | X;
perm |= W;
perm &= ~R;
perm ^= X;
printf("%d %d", perm, (perm & W) != 0);- A. 2 1
- B. 3 1
- C. 2 0
- D. 6 1
Correct answer: A. 2 1
R | X = 5 (101). |= W sets bit 1 → 7. &= ~R clears bit 2 → 3. ^= X toggles bit 0 off → 2. Only W is left, so the test prints 1. '3' forgets that XOR toggles a bit that is already set.
More C Programming questions
- What is printed? c printf("%d", 5["abcdef"] - 'a');
- What is printed? c const char s = ""; int n = 0; for (int i = 0; i < strlen(s) - 1; i++) { n++; if (n > 5) break; } printf("%d", n);
- What is printed? c int pm(int b, int e, int m) { if (e == 0) return 1 % m; int h = pm(b, e / 2, m); h = h h % m; return e % 2 ? h b % m…
- What is printed? c #define STR(x) #x printf("%zu", strlen(STR( a + b )));
- What is printed? c char g[3][4] = {"abc", "def", "ghi"}; for (int j = 0; j < 3; j++) putchar(g[2 - j][j]);
- A file report.txt already exists and holds data. What does fopen("report.txt", "w") do?