What will be the output of the following C code?
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p->name = "xyz";
p->next = NULL;
ptrary[0] = &p;
printf("%s\n", p->name);
return 0;
}
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p->name = "xyz";
p->next = NULL;
ptrary[0] = &p;
printf("%s\n", p->name);
return 0;
}A. Compile time error
B. Segmentation fault/code crash
C. xyz
D. Undefined behaviour
Answer: Option A
Related Questions on Structure and Union
Which of the following can be a member of a structure?
A. Function
B. Another structure
C. Enumeration
D. All of the above

Join The Discussion