ProgrammingHard

In C, what is the value of a freshly malloc'd int that the program never initialises?

  1. A. Indeterminate, so reading it is undefined behaviour
  2. B. Zero, as with calloc
  3. C. The value of the previous allocation
  4. D. Always the bit pattern 0xCD

Correct answer: A. Indeterminate, so reading it is undefined behaviour

malloc leaves memory uninitialised. Reading an indeterminate value is undefined, and debug builds only pretend it has a pattern.

More C Programming questions

Exams that ask this topic