Which call correctly allocates space for an array of 10 double values?
Correct answer D. malloc(10 * sizeof(double))
Explanation
malloc takes a size in bytes, so you multiply the element count by the size of one element: 10 * sizeof(double), usually 80 bytes. malloc(10) gives only 10 bytes, and malloc(sizeof(double)) holds a single value. sizeof(double *) is the size of a pointer, which happens to be 8 on 64-bit systems but is the wrong type and fails on 32-bit ones.
Answer checked How we write and check questions
Discussion