ProgrammingHardTCS NQT · Infosys pattern
What is printed? Assume 32-bit int.
What is printed? Assume 32-bit int.
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 and bit 4 gives 0b10100 = 20, then clearing bit 2 with &= ~(1<<2) removes that bit, leaving only bit 4 set: 0b10000 = 16.
More C Programming questions
- What can be said about this program? c #include <stdlib.h> int main(void) { int p = malloc(sizeof(int)); free(p); free(p); }
- What is printed? c void modify(int arr[10]) { printf("%lu ", sizeof(arr)); } int main(void) { int a[10]; printf("%lu ", sizeof(a))…
- What is printed? const qualifies what p points to, not p itself. c int x = 5, y = 10; const int p = &x; p = &y; printf("%d", p);
- What is printed? c int a = 10; int p = &a; int q = p; p = NULL; printf("%d", q);
- What is printed? c int f(int n) { if (n == 0) return 0; return n + f(n - 1); } int main(void) { printf("%d", f(4)); }
- What is printed? c int fib(int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } int main(void) { printf("%d", fib(6)); }