ProgrammingVery hardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint32_t v = 0xDEADBEEFu;
v ^= v >> 16;
v ^= v >> 8;
v ^= v >> 4;
v ^= v >> 2;
v ^= v >> 1;
printf("%u", v & 1u);
}- A. 1
- B. 0
- C. 2
- D. 24
Correct answer: B. 0
XOR-folding the word down to its lowest bit yields the parity of its set bits. 0xDEADBEEF has 24 set bits, which is even, so the parity is 0.
More C Programming questions
- Assume uint16t and int are 16 and 32 bits. What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint16t a = 40000, b…
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 3, c = 0; unsigned i = n - 1; for (; i >= 0 && c < 10; i--) c++…
- What is printed? c #include <stdio.h> int main(void) { int a[3][4]; int n = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++)…
- Assume int is 4 bytes. What is printed? c #include <stdio.h> int main(void) { int a[10]; int p = &a[7], q = &a[2]; printf("%ld %ld"…
- Assume a pointer is 8 bytes and int is 4 bytes. What is printed? c #include <stdio.h> void f(int v[]) { printf("%zu ", sizeof v); } int…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "hi0there"; printf("%zu %zu", sizeof s, strlen(s)); }