🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Pointers and 2D Arrays: all 15 questions

Quiz: Pointers and 2D Arrays · Question 7 of 15

Why is an array of pointers better than char names[100][50] for storing names of different lengths?

Why is an array of pointers better than char names[100][50] for storing names of different lengths?

  1. A.It sorts the names automatically
  2. B.Each pointer can point to a string of exactly the size it needs, so short names waste no space
  3. C.It is the only way to use printf with %s
  4. D.2D char arrays cannot store strings
Answer & explanation

Correct answer: Each pointer can point to a string of exactly the size it needs, so short names waste no space

A 2D char array reserves 50 bytes for every name; pointers let each string be its own length.

Can you get the rest right without peeking?

Take the timed Quiz: Pointers and 2D Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →