All mock tests are FREE till 31 December — register to save your progress

On a 32-bit x86 machine: typedef struct { union { unsigned char a; unsigned short b; } U; unsigned char c; } S; S B[10]; S *p = &B[4]; S *q = &B[5]; p->U.b = 0x1234; (S takes 32 bits). If M is q − p and N is (int)&(p->c) − (int)p, then (M, N) is

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. (1, 2)

Explanation

q − p counts elements, so M = 1. The union takes 2 bytes (a short), so c sits at byte offset 2: N = 2.

More Programming Languages and Computer Graphics questions