ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
long long a = 1LL << 40;
int b = (int)(a >> 20);
printf("%d", b);
}- A. 1099511627776
- B. 0
- C. 2097152
- D. 1048576
Correct answer: D. 1048576
a >> 20 is 2^40 / 2^20 = 2^20 = 1048576, which fits in int, so the conversion is exact.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {4, 2, 5, 1}; for (int i = 0; i < 3; i++) printf("%d ", a[i] > a[i + 1] ?…
- How many pairs (i, j) with i < j have a[i] XOR a[j] equal to 5 for a = {1, 2, 3, 4}? Compute with this program. c #include <stdio.h> int…
- What is printed? c #include <stdio.h> struct N { int v; struct N nx; }; struct N rev(struct N h, struct N prev) { if (!h) return prev…
- What is printed? c #include <stdio.h> int main(void) { unsigned long long r = 1, b = 7; int e = 222; while (e) { if (e & 1) r = r b %…
- What is printed? c #include <stdio.h> int main(void) { unsigned h = 0; for (const char s = "abcdefgh"; s; s++) h = (h << 5) ^ (unsigned…
- What is printed? c #include <stdio.h> int pc(int x) { int c = 0; while (x) { c += x & 1; x >>= 1; } return c; } int cmp(const void a…