ProgrammingModerate
With a 4-byte int and an 8-byte pointer, natural alignment, what is sizeof(struct N) for struct N { int v; struct N *next; };?
- A. 12
- B. 16
- C. 8
- D. 20
Correct answer: B. 16
v takes 4 bytes, then 4 bytes of padding align the pointer, which takes 8 bytes. The total is 16.
More C Programming questions
- A linked list is built by appending n nodes one by one, each time walking from the head to the last node. About how many node visits does…
- A stack is implemented with a singly linked list, pushing at the head. The operations are push 1, push 2, pop, push 3, push 4, pop, pop…
- A queue is kept as a singly linked list with head and tail pointers. Enqueue 1, 2, 3, dequeue twice, enqueue 4, then dequeue once. Which…
- Which loop correctly frees every node of a singly linked list whose head is p?
- A recursive function prints a list after its recursive call returns, as in print(n) { if (!n) return; print(n->next); putchar(n->v + '0')…
- In a 6-node list with values 10, 20, 30, 40, 50, 60, the standard slow and fast pointer method (slow moves one step, fast two steps, while…