ProgrammingHardInfosys · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
printf("%d %u", 1 << 30 >> 29, (unsigned)-1 >> 30);
}- A. 2 1
- B. 1 3
- C. 4 3
- D. 2 3
Correct answer: D. 2 3
Shifts associate left to right, so (1 << 30) >> 29 = 2. (unsigned)-1 is all ones, and shifting right by 30 leaves the two top bits, 3.
More C Programming questions
- What is printed? c #include <stdio.h> int bs(const int a, int lo, int hi, int k) { if (lo > hi) return -1; int m = lo + (hi - lo) / 2; if…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {5, 9, 12, 7}; int p[5] = {0}; for (int i = 0; i < 4; i++) p[i + 1] =…
- 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 mul(int a, int…
- What is printed? c #include <stdio.h> int main(void) { signed char c = -1; unsigned char d = c; printf("%d %d", c == d, (int)d); }
- What is printed? c #include <stdio.h> int main(void) { int h = -17; unsigned idx = (unsigned)h % 16u; printf("%u", idx); }
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> struct Person { char name[4]; int age; }; int cmp(const void…