I want to directly assign values to a 2d array of pointers for which the memory is allocated dynamically. But the compiler shows 2 warning and 1 error.
2 Warnings on line 11 and 12: int differs in level of indirection from int*.
error on line 13: Syntax error : '{'
Here is my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int r , c, rc;
int* pmat1[3][3], pmat2[3][3], pmat3[3][3];
*pmat1[3] = (int*)calloc(3,sizeof(int));
*pmat2[3] = (int*)calloc(3,sizeof(int));
*pmat3[3] = (int*)calloc(3,sizeof(int));
*pmat1[3][3] = { {1,1,1}, {0,0,0}, {2,2,2} };
return 0;
}
What error am I making here?
pmat2andpmat3are 2d integer arrays. Probably you want to declare them in this way:int* pmat1[3][3], *pmat2[3][3], *pmat3[3][3].int* x, y, z;is equivalent toint* x; int y; int z;.