C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 2)
2.
Point out the error in the program?
typedef struct data mystruct;
struct data
{
int x;
mystruct *b;
};
Answer: Option
Explanation:
Here the type name mystruct is known at the point of declaring the structure, as it is already defined.
Discussion:
17 comments Page 1 of 2.
Zddd said:
7 years ago
@Swathi.
Nice Explanation. Thanks.
Nice Explanation. Thanks.
Gavldl Srikanth said:
8 years ago
Nice Explanation. Thanks.
Rahul said:
8 years ago
Structure is a user define data type so when a user defines a data type like
struct Student
{
int roll;
char name[10];
};
The statement struct Student declares a structure,
struct student s; // EQUIVALENT TO int n;
but
typedef is an abbreviation of data type definition.If a structure is declared using a typedef statement, it becomes a new data type.
typedef struct // STRUCTURE HAS BEEN DECLARED USING typedef STATEMENT
{
int roll;
char name[10];
}Student;
Now we only use
Student s; // instead of struct Student s; we don't have to use struct keyword again and again;
Hope this will help.
struct Student
{
int roll;
char name[10];
};
The statement struct Student declares a structure,
struct student s; // EQUIVALENT TO int n;
but
typedef is an abbreviation of data type definition.If a structure is declared using a typedef statement, it becomes a new data type.
typedef struct // STRUCTURE HAS BEEN DECLARED USING typedef STATEMENT
{
int roll;
char name[10];
}Student;
Now we only use
Student s; // instead of struct Student s; we don't have to use struct keyword again and again;
Hope this will help.
Abdullah said:
9 years ago
I get this Error while compiling:
undefined reference to `WinMain@16'| !!!!
Can anyone help me?
undefined reference to `WinMain@16'| !!!!
Can anyone help me?
Ishita said:
9 years ago
How does it know that struct data exist, since it is declared and defined later on?
(1)
Anand said:
9 years ago
"mystruct" will be replaced by "struct data" which will become a self-referential structure.
Mohan said:
1 decade ago
Typedef is used for user defined data types to make our own data type.
Janani said:
1 decade ago
What is the use of using this typedef?
Swathi said:
1 decade ago
typedef is used to give alternative name for any of the data type.
In this example "typedef struct data mystruct" indicates that mystruct is same as type struct data.
Hence mystruct *b means b is a pointer of the type struct data.
In this example "typedef struct data mystruct" indicates that mystruct is same as type struct data.
Hence mystruct *b means b is a pointer of the type struct data.
Krishna said:
1 decade ago
Please explain the typedef?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers