ProgrammingHardProduct company OA · GATE CS

Which of these statements about C's dynamic-memory functions are correct? (i) realloc(NULL, n) behaves like malloc(n). (ii) If realloc fails it returns NULL and frees the original block. (iii) free(NULL) does nothing. (iv) The memory returned by calloc is filled with zero bytes.

  1. A. (i), (iii) and (iv) only
  2. B. All four
  3. C. (i) and (iv) only
  4. D. (iii) and (iv) only

Correct answer: A. (i), (iii) and (iv) only

(ii) is the trap: when realloc fails it returns NULL and leaves the original block untouched and still allocated, which is why you assign its result to a temporary first. The other three are guaranteed by the standard.

More C Programming questions

Exams that ask this topic