How do you allocate a matrix using a single pointer in C?(r and c are the…

2025

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

Answer: B. int *arr = (int *)malloc(r * c * sizeof(int));Answer: b Explanation: To allocate a matrix using a single pointer in C, you must calculate the total memory size required. This is done by multiplying the…

  1. A.

    int *arr = malloc(r * c * sizeof(int));

  2. B.

    int *arr = (int *)malloc(r * c * sizeof(int));

  3. C.

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

  4. D.

    int *arr = (int *)malloc(r * c * sizeof(arr));

Attempted by 206 students.

Show answer & explanation

Correct answer: B

Answer: b Explanation: To allocate a matrix using a single pointer in C, you must calculate the total memory size required. This is done by multiplying the number of rows (r) and columns (c) by the size of the data type (e.g., sizeof(int)). The allocation is performed using malloc(r * c * sizeof(int)), which reserves a contiguous block of memory for the matrix elements.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…