ProgrammingVery hardProduct company OA
What is printed?
What is printed?
union U { int i; float f; } u = {3.9};
printf("%d", u.i);- A. 4
- B. 3
- C. The bit pattern of the float 3.9 read as an int
- D. Compilation error
Correct answer: B. 3
A brace initialiser for a union initialises its first member, here the int i. 3.9 is converted to int by truncation, so u.i = 3. The float member is never written, and no type punning takes place.
More C Programming questions
- What is printed? c int i = 0, c = 0; while (i < 10 && ++c && i++ % 3 != 2); printf("%d %d", i, c);
- Given this allocation, which code frees everything without leaking or touching freed memory? c int m = malloc(3 sizeof m); for (int i = 0…
- With char a = "hi", b = "hi"; what can be said about the value of a == b?
- What is printed? c int c = 0; for (int i = 1; i <= 4; i++) for (int j = i; j <= 4; j += i) c++; printf("%d", c);
- Assume 16-bit unsigned short and 32-bit int. What is printed? c unsigned short v = 0x1234; unsigned short w = (unsigned short)(v << 8 | v…
- What is printed? c void conv(int n, int b) { if (n >= b) conv(n / b, b); putchar("0123456789ABCDEF"[n % b]); } int main(void) { conv(255…