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

Memory Allocation Questions and Answers

Answer: A

Correct answer: The number of elements and the size of each element

calloc() multiplies the two arguments to find the total number of bytes, then clears them. Splitting the request in two lets the library detect an overflow in that multiplication, which a single-argument malloc() call cannot do.

Please log in or register to report this question.

102.

If malloc() successfully allocates memory it returns the number of bytes it has allocated.

Answer: B

Correct answer: FALSE

malloc returns a pointer to the allocated block, not a count of bytes. On success it is the address of the storage; on failure it is null.

The number of bytes is what the caller supplied as the argument, so returning it would convey nothing. There is in fact no portable way to ask how large an allocated block is once it has been made, which is why programs that need to know must record the size themselves alongside the pointer.

Please log in or register to report this question.

Loading…
Tags: Memory Allocation Questions and Answers || Memory Allocation MCQ Questions and Answers || Memory Allocation GK Questions and Answers || Memory Allocation GK MCQ Questions || Memory Allocation Multiple Choice Questions and Answers || Memory Allocation GK || GK on Memory Allocation || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming