ProgrammingHardIBM · Deloitte pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int flags = 0;
flags |= (1 << 2);
flags |= (1 << 4);
flags &= ~(1 << 2);
printf("%d", flags);- A. 16
- B. 20
- C. 4
- D. 12
Correct answer: A. 16
Setting bit 2 gives 0b00100=4. Setting bit 4 gives 0b10100=20. Clearing bit 2 with &= ~(1<<2) removes it: 0b10000=16. This is the standard set/clear-bit idiom.
More C Programming questions
- What is printed? c #if defined(DEBUG) && !defined(RELEASE) #define LOG(x) printf("[debug] %sn", x) #else #define LOG(x) #endif int main()…
- What is printed? c int a = 10; int b = (a > 5) ? (a < 20 ? 1 : 2) : 3; printf("%d", b);
- What is printed? c #define N 5 #undef N #define N 10 int main() { printf("%d", N); }
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int pp = &p; pp = 20; printf("%d %d %d", a, p, pp);
- Assume a 64-bit LP64 ABI. What is printed? c char names[] = {"Alice", "Bob", "Carol"}; char p = names; p++; printf("%s %s", p, (names + 2));
- Assume a 64-bit LP64 ABI. What is printed? c int a[5] = {10, 20, 30, 40, 50}; int p = a + 4; int q = a; printf("%ld %d %d", p - q, (p…