I am making a program to allocate a 20x20 array of characters. Here is what I did:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *a=(char*) calloc(20,sizeof(char[20]));
a[0]="abcd";
printf("%s\n",a[0]);
return 0;
}
The output of the above code is (null)
. Can anybody please explain this? According to me, I am allocating a pointer a
20 spaces of size 20 each. So a[0]
technically has enough memory to store "abcd", yet the output is null
.