I wrote two program that I thought were the same but apparently they are not and I cant figure out why.
the first program(works as expected):
#include <stdio.h>
void main()
{
char *p[2][3]={"xyz","wvu","ts","rqponm","lkgihgfe","dcba"};
printf("\n%c\n",(***p)); /*z*/
printf("\n%c\n",((*(*(p+1)+1))[6]));/*f*/
printf("\n%c\n",(**(p[1]+2)));/*d*/
printf("\n%c\n",(**p[1]));/*r*/
printf("\n%c\n",(*(p[1][2]+2)));/*b*/
}
the second program:
#include <stdio.h>
void main()
{
char *p[2][3]={{'x','y','z','\0'},"wvu","ts","rqponm","lkgihgfe","dcba"};
printf("\n%c\n",(***p)); /*z*/
printf("\n%c\n",((*(*(p+1)+1))[6]));/*f*/
printf("\n%c\n",(**(p[1]+2)));/*d*/
printf("\n%c\n",(**p[1]));/*r*/
printf("\n%c\n",(*(p[1][2]+2)));/*b*/
}
when I Compile this program I get a warning: excess elements in array initializer. when I run it I get an error: Segmentation fault (core dumped).
obviously the problem is in {'x','y','z','\0'} but I thought its the same as "xyz".