Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the return type of malloc() or calloc()?

  • A.int *
  • B.int **
  • C.void *
  • D.void **

Answer: C

Correct answer: void *

Both allocators return void *, a pointer to untyped storage. The caller assigns it to a pointer of whatever type it needs, and in C that conversion is implicit.

The design is what lets a single pair of functions serve every type in the language. It also means the allocator has no idea what will be stored in the block - alignment is guaranteed to suit any type, but the size must be computed by the caller, which is why sizeof appears in almost every call.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.