ProgrammingHard

Which C code correctly inserts a node n at the front of bucket h of an array of struct node *table[]?

  1. A. table[h]->next = n;
  2. B. n->next = table[h]; table[h] = n;
  3. C. table[h] = n->next;
  4. D. table[h] = n; n->next = table[h];

Correct answer: B. n->next = table[h]; table[h] = n;

The new node must point to the old head before it becomes the head. The third version overwrites the head first and loses the chain.

More C Programming questions

Exams that ask this topic