ProgrammingModerate
int **m = malloc(3 * sizeof *m); for (int i = 0; i < 3; i++) m[i] = malloc(4 * sizeof **m); What is the number of allocation calls made in total?
- A. 3
- B. 4
- C. 7
- D. 12
Correct answer: B. 4
One malloc for the array of row pointers, and one for each of the three rows, makes 4 calls.
More C Programming questions
- A doubly linked list node has prev and next. What must happen before freeing the node p in the middle of the list?
- A linked stack stores nodes with a pointer to the top. Push and pop run in O(1). What is the cost of freeing the whole stack when it has n…
- A list of 10^6 nodes is built by prepending, and then each node is looked up by value in a loop. What is the total cost of 10^6 lookups?
- int p = malloc(10 sizeof p); free(p); free(p); What is the result?
- In C, which of these are true about malloc's return value (assume the request succeeds)?
- A program allocates an int array of size n with malloc(n sizeof(int)). For n = 2^31, on a platform with 32-bit sizet, what can go wrong?