ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int x = 5;
int *p = &x;
*p = *p << 2 | 1;
printf("%d", x);
}- A. 20
- B. 22
- C. 21
- D. 17
Correct answer: C. 21
Shift binds tighter than bitwise OR, so the value is (5 << 2) | 1 = 20 | 1 = 21. The write through p updates x.
More C Programming questions
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint32t x = ~0u >> 3; int c = 0; for (; x; x &= x - 1) c++…
- What is printed? c #include <stdio.h> unsigned long long g(int n) { if (n < 2) return 0; return g(n - 1) + g(n - 2) + 1; } int main(void)…
- int c = 0; for (int i = 0; i < 4; i++) for (int j = 0; j < i i; j++) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 12; i++) c += 12 / i; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 10; i++) for (int j = i; j <= 10; j += i) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i i <= 50; i++) c++; printf("%d", c); What is printed?