Question discussion

What does the malloc() function of C return when the memory is allocated successfully?

2562Medium DSSSB TGT Computer Science 0 replies 1 views
0

What does the malloc() function of C return when the memory is allocated successfully?

  • AAn int that gives the number of bytes allocated
  • BA void pointer to the allocated block of memory
  • CA char pointer to the last byte of the block
  • DThe value 0 always
Correct answer: B

Explanation

malloc returns a generic pointer of type void * to the beginning of the block, which can be assigned to a pointer of any type in C, and it returns NULL if the request cannot be satisfied.

Discussion 0

Nobody has replied yet. Start the discussion!