ProgrammingVery hardCognizant GenC · C · Advanced
What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { struct P { int id; char grade; }; struct P recs[2] = {{1, 'A'}, {2, 'B'}}; printf("%d %c %zu", recs[1].id, recs[1].grade, sizeof(recs)); return 0; }
- A. 2 B 16
- B. 2 B 8
- C. 1 A 16
- D. 2 B 10
Correct answer: A. 2 B 16
struct P pads to 8 bytes (int id=4, char grade=1, 3 padding so the struct is 4-byte aligned); an array of 2 is 16 bytes; recs[1] is {2,'B'}.
More C Programming questions
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…