← 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?
- A.It sorts the names automatically
- B.Each pointer can point to a string of exactly the size it needs, so short names waste no space
- C.It is the only way to use printf with %s
- 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 →