When I tried to compile the following program, it gives me no output on screen:
#include<stdio.h>
int main ()
{
struct d1
{
char arr [10];
int num;
};
struct d2
{
struct d1 name;
int age;
}p1;
p1.name={("JANE",8)};
printf ("%s",&p1.name.arr[0]);
}
I think problem is due to line p1.name={("JANE",8)};
But I think I have written everything right. By writing this line I tried to assign value to a member,"name" of variable p1 having structure type d2. And as name is itself a structure of type d1 having two members, so I assigned two values JANE and 8 to arr [10] and num members of name respectively.
I even tried with
p1.name={{"JANE",8}}; //For this it gives error
p1.name={("JANE",8),20}; //For this it compiles but no output
p1.name={{"JANE",8},20}; //again error
That 20 is value of p1's member "age". While trying to print value p1.name.age it gives 0 instead of20.
What's wrong? Is there any syntax error or a conceptual error?
{"JANE",8}is. Usep1.name=(struct d1){"JANE",8};