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 2 of 2.
Mohan said:
1 decade ago
Typedef is used for user defined data types to make our own data type.
Anand said:
9 years ago
"mystruct" will be replaced by "struct data" which will become a self-referential structure.
Ishita said:
9 years ago
How does it know that struct data exist, since it is declared and defined later on?
(1)
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?
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.
Gavldl Srikanth said:
8 years ago
Nice Explanation. Thanks.
Zddd said:
7 years ago
@Swathi.
Nice Explanation. Thanks.
Nice Explanation. Thanks.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers