Multiple choice technology programming languages

Which of the following differences between malloc and calloc are true? 1) malloc allocates number of bytes passed as argument 2) calloc allocates the product of number of elements multiplied by the size of each element, which are both passed as arguments. 3) both malloc and calloc return void* 4) both malloc and calloc initialize allocated memory to all 0

  1. 1, 2, 3, 4

  2. 1, 2, 3

  3. 1,2

  4. 1

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

malloc accepts a single size argument in bytes, calloc accepts the number of items and the size of each item, and both return a void* pointer. However, only calloc initializes the allocated memory to all zeros, while malloc leaves it uninitialized. Thus, statement 4 is false and statements 1, 2, and 3 are true.