🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Storage Classes in C: all 15 questions

Quiz: Storage Classes in C · Question 10 of 15

A function returns the address of its local array char buf[20]; (not static). What is the problem?

A function returns the address of its local array char buf[20]; (not static). What is the problem?

  1. A.None — arrays are always global
  2. B.The array is copied, which is slow
  3. C.buf is destroyed when the function returns, so the caller gets a dangling pointer
  4. D.It does not compile in any compiler
Answer & explanation

Correct answer: buf is destroyed when the function returns, so the caller gets a dangling pointer

An auto local dies with its function. Make it static, use malloc, or let the caller pass a buffer.

Can you get the rest right without peeking?

Take the timed Quiz: Storage Classes in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →