adplus-dvertising
frame-decoration

Question

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).int *arr = (int *)malloc(r * c * sizeof(int));

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)