I create multi dimensioanl array and write it to console
char a[5][10];
strcpy(a[0], "111111");
strcpy(a[1], "211112");
strcpy(a[2], "311113");
strcpy(a[3], "411114");
strcpy(a[4], "511115");
printf("size : %d \n", sizeof(a));
int i;
for(i = 0; i < 5; i++)
{
printf("%d : %s \n",i,a[i]);
}
result is
size : 50
0 : 111111
1 : 211112
2 : 311113
3 : 411114
4 : 511115
then I copy the array to another array, and write both of them to console
char a[5][10];
char b[][10]={"0"};
strcpy(a[0], "111111");
strcpy(a[1], "211112");
strcpy(a[2], "311113");
strcpy(a[3], "411114");
strcpy(a[4], "511115");
memcpy(&b,&a,sizeof(a));
printf("sizeof(a) : %d \n", sizeof(a));
int i;
for(i = 0; i < 5; i++)
{
printf("%d : %s \n",i,a[i]);
}
printf("sizeof(b) : %d \n", sizeof(b));
for(i = 0; i < 5; i++)
{
printf("%d : %s \n",i,b[i]);
}
result is:
sizeof(a) : 50
0 :
1 :
2 :
3 :
4 : 511115
sizeof(b) : 10
0 : 111111
1 : 211112
2 : 311113
3 : 411114
4 : 511115
what happened variables in a array ? why contents of a array are empty ?
I use Ubuntu 14.04
and gcc version is (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4