Vidyalelo
Data Structure · Q158

Arrays in Data Structures

Programming · Data Structure · question 158

Q158

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

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board