int main()
{
int a;
typedef struct
{
int i;
int j;
}type1;
typedef type1 type[10]; //Please explain this line ?
typedef struct
{
int l;
type c;
}type2;
type2 x;
x.c[0].i=1; //How can we write this??
x.c[0].j=2;
x.c[2].j=3;
printf("%d",x.c[2].j);
return 0;
}
Program is compiling successfully which I’m expectecting not to because of
typedef type1 type[10];
Please explain the behavior of typeded here.All I know is that we can define an alias with the help of typedef.
output:3
The way to read
typedefis as a regular variable declaration, with the variable’s type being the type that is being given an alias, and the variable name being the name of the new alias.So, in
if we drop the
typedefwe get:This clearly defines
typeto be an array of 10type1. So, thetypedefis then introducing the nametypefor the type “array of 10type1“.