If I declare a two dimensional array as
#include <stdio.h>
#include <stdlib.h>
int main() { int c=5;int r=6;
int **a=(int **) malloc (c*sizeof(int *));
int i,j;
for (i=0;i<c;i++){
*(a+i)=(int *) malloc (r*sizeof (int));
}
}
The above program works successfully.
#include <stdio.h>
#include <stdlib.h>
int main() { int c=5;int r=6;
int **a;
**a=(int **) malloc (c*sizeof (int *));
int i,j;
for (i=0;i<c;i++){
*(a+i)=(int *) malloc (r*sizeof (int));
}
}
But the compiler shows an error in the above program.
Why so? Any help would be greatly appreciated.