- free(matrix[0]);
- for(int i=0; i<rows; i++) free(matrix[i]); free(matrix);
- for(int i=0; i<cols; i++) free(matrix[i]); free(matrix);
Explanation:
The accurate choice is (c). In the C programming language, a double pointer is commonly employed to represent a two-dimensional array. Each pair of pointers consists of one pointer for every dynamically allocated array (row).
- What is the specific value stored in C1 within the provided code snippet?
#include<stdio.h>
void matrixMultiply(int A[][2],int B[][2],int C[][2],int p,int q,int m)
{
int i,j,k;
for(i=0;i<p;i++)
{
for(j=0;j<m;++j)
{
C[i][j]=0;
for(k=0;k<q;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
}
int main()
{
int A[2][2]={{1,2},{3,4}};
int B[2][2]={{2,0},{1,2}};
int C[2][2];
matrixMultiply(A,B,C,2,2,2);
printf("C[1][1]=%d\n", C[1][1]);
return 0;
}
Explanation:
The correct answer is option (d). Following matrix multiplication, the program outputs C1's value. Here, the value is computed by taking the dot product of the second row of matrix A({3,4 }) and the second column of matrix B({0,2}): 30 + 42 =0+8, which is equal to zero.
- What can be the main reason to use a matrix multiplication algorithm over the standard O(n^3)approach?
- To use less memory.
- To reduce the number of matrix multiplications.
- To handle larger matrices more efficiently.
- To make the code easier to understand.
Explanation:
- Regarding dynamic memory allocation for a 2D array in C, which of the following statements is true?
- int *matrix=malloc(rowssizeOf(int *));
- int matrix = malloc(rows cols sizeof(int));
- int *matrix = malloc(cols sizeof(int *));
- int matrix = malloc(rows sizeof(int));
Explanation:
- How can the resultant matrix hold the value of the multiplication of two matrices, A and B?
- Ci=Ai*Bi;
- Ci+=Ai*Bk;
- Ci=Ai*Bk;
- Ci-=Ai*Bi;
Explanation:
The accurate choice is (b). Every following matrix is calculated by summing up the outcomes of the corresponding elements in the rows of the initial matrix and the columns of the second matrix.