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;
};
Error: in structure declaration
Linker Error
No Error
None of above
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.

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.

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.

Coders said:   1 decade ago
typedef struct data mystruct;

Means we are making mystruct a member of struct at the time of declaration.

Amit kumar said:   1 decade ago
The typedef a simply definition of struct types which can be used for short name of structure definition.

Abdullah said:   9 years ago
I get this Error while compiling:

undefined reference to `WinMain@16'| !!!!

Can anyone help me?

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)

Mohan said:   1 decade ago
Typedef is used for user defined data types to make our own data type.

Gowthami said:   1 decade ago
Hello please explain the line "typedef struct data mystruct;".

Shweta said:   1 decade ago
Why we use typedef and what is it's meaning?


Post your comments here:

Your comments will be displayed after verification.