ProgrammingVery hard

In C, which of these are true about malloc's return value (assume the request succeeds)?

  1. A. It is always zeroed
  2. B. It is always an int pointer
  3. C. It is suitably aligned for any object type and may be assigned to a pointer of any object type after a cast or implicit conversion from void *
  4. D. It must be cast to char * before use

Correct answer: C. It is suitably aligned for any object type and may be assigned to a pointer of any object type after a cast or implicit conversion from void *

malloc returns a void * aligned for any standard type. Its contents are indeterminate, and in C it needs no cast.

More C Programming questions

Exams that ask this topic