ProgrammingHard

int *p = malloc(10 * sizeof *p); free(p); free(p); What is the result?

  1. A. The second free is a no-op
  2. B. Undefined behaviour, because p is freed twice
  3. C. It frees 20 ints, since the size doubles
  4. D. A runtime error is guaranteed

Correct answer: B. Undefined behaviour, because p is freed twice

Freeing the same pointer twice is undefined. C does not promise a no-op or an error.

More C Programming questions

Exams that ask this topic