ProgrammingModerate

A malloc'd block of 16 bytes is written past its end by 4 bytes. What is the correct description?

  1. A. Undefined behaviour, which can corrupt the heap and may not crash immediately
  2. B. It is harmless, because malloc adds padding
  3. C. It is guaranteed to crash at once
  4. D. It writes into the next allocation in a defined way

Correct answer: A. Undefined behaviour, which can corrupt the heap and may not crash immediately

Writing past the end of an allocation is undefined. The damage may stay hidden until a later allocation or free fails.

More C Programming questions

Exams that ask this topic