ProgrammingHard

struct N { int v; struct N *next; } *a = NULL; for (int i = 1; i <= 3; i++) { struct N *n = malloc(sizeof *n); n->v = i; n->next = a; a = n; } printf("%d", a->next->v); What is printed?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 0

Correct answer: B. 2

Head insertion makes the last inserted node, 3, first. Its next node is 2, which is printed.

More C Programming questions

Exams that ask this topic