[Solved] How do you allocate a matrix using a single pointer in C?

How do you allocate a matrix using a single pointer in C?

(r and c are the number of rows and columns respectively)

a) int *arr = malloc(r * c * sizeof(int));
b) int *arr = (int *)malloc(r * c * sizeof(int));
c) int *arr = (int *)malloc(r + c * sizeof(int));
d) int *arr = (int *)malloc(r * c * sizeof(arr));

Answer: b
Explanation: Total number of elements in the matrix will be r*c

Comments