Reputation: 1058
I have come to know from book that for declaring a structure variable it is necessary a preceding struct
keyword, but without that preceding struct
in my Bloodshed\DevC++ compiler variable can be declared without any error like following,
struct stype
{
int ival;
float fval;
double dval;
};
and in main,
stype s;
s.ival=10;s.dval=23.23;s.fval=233.23;
printf("%d %f %lf\n",s.ival,s.fval,s.dval);
This correctly prints what should be printed. Is there any modification behind using this struct
keyword in variable declaration or what? why this code working??
Upvotes: 2
Views: 387
Reputation: 21435
In C it is obligatory (or you can use a typedef). In C++ not.
Upvotes: 8