C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Yes / No Questions (Q.No. 10)
10.
Will the following declaration work?
typedef struct s
{
int a;
float b;
}s;
Discussion:
10 comments Page 1 of 1.
Chinna said:
1 decade ago
If any problem using same structure variable like structure name.
Please explain it.
Please explain it.
Wikiok said:
1 decade ago
typedef long int LI;
int main ()
{
LI LI; //Works, no error!!!
LI=10;
}
So defined type's name can be used as a variable name.
int main ()
{
LI LI; //Works, no error!!!
LI=10;
}
So defined type's name can be used as a variable name.
Gopi said:
1 decade ago
It will not work because structure variable name should not be the same as structure name.
Shrinivas Patgar said:
1 decade ago
I think it will not work instead of this.
typedef struct
{ int a ;
float b;
}s;
will work.
typedef struct
{ int a ;
float b;
}s;
will work.
Om prakash said:
1 decade ago
Yes I agree with @Shrinivas patgar. We use typedef for anonymous structure (no name for the structure).
Prince Bansal said:
1 decade ago
Try this one:
int main()
{
struct s
{
int a;
float b;
};
struct s s;
s.a=10;
printf("%d",s.a);
}
This is working.
Can anyone explain it?
int main()
{
struct s
{
int a;
float b;
};
struct s s;
s.a=10;
printf("%d",s.a);
}
This is working.
Can anyone explain it?
Rishi said:
9 years ago
Yes, it will work.
The reason is that typedef is used to assign an alternative name to the user to define data types as well.
So, here typedef creates the name "s" (structure) which can be used again in the program.
The reason is that typedef is used to assign an alternative name to the user to define data types as well.
So, here typedef creates the name "s" (structure) which can be used again in the program.
Zdd said:
7 years ago
I agree @Wikiok @Rishi.
Ajayv said:
7 years ago
How to access members of this anonymous structure @Shrinivas Patgar.
Himanshu said:
3 years ago
Yes, you are right @Rishi.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers