I'm learning the C language. Can anybody help me to understand the following result:
int main()
{
struct xx
{
int x;
char name[];
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
return 0;
}
output:- Segmentation fault
I wrote another code which is:
struct Foo
{
char *pName;
};
int main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
return 0;
}
output : Segmentation Fault (core dumped);
Why am I getting segmentation fault? What's wrong with the code? What is the meaning of core dumped ?