ProgrammingVery hard
struct W { int x; }; struct W w1 = {3}, w2 = {3}; printf("%d", w1.x == w2.x && memcmp(&w1, &w2, sizeof w1) == 0); What is printed (no padding in this struct)?
- A. 0
- B. 3
- C. 1
- D. 2
Correct answer: C. 1
Both members hold 3 and the struct has no padding, so memcmp also reports equality. The output is 1.
More C Programming questions
- struct Pack { char a; int b; } p = {'x', 5}; unsigned char raw = (unsigned char )&p; printf("%d", raw[0] == 'x'); What is printed?
- struct Bits { int f : 4; }; struct Bits b; b.f = 3; printf("%d", b.f); What is printed in C for a signed 4-bit field holding 3?
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xB5, y = 0x4E, z = x ^ y, c = 0; while (z) { z &= z - 1; c++; }…
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t v = 0; v |= 1u << 3; v |= 1u <<…
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t x = 0x0003, r = 0; for (int…
- What is printed? c #include <stdio.h> int t[256]; int main(void) { for (int i = 1; i < 256; i++) t[i] = t[i >> 1] + (i & 1); printf("%d…