ProgrammingVery hard

A malloc'd array of 10 structs is later passed to free(&arr[3]). What is the correct description?

  1. A. It frees only the fourth struct
  2. B. It is harmless because free ignores the argument
  3. C. Undefined behaviour, because free must receive the exact pointer that malloc returned
  4. D. It frees the entire array and sets arr to NULL

Correct answer: C. Undefined behaviour, because free must receive the exact pointer that malloc returned

free accepts only a pointer that malloc, calloc or realloc returned, or NULL. A pointer into the middle is not valid.

More C Programming questions

Exams that ask this topic