Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.