C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 1)
1.
Point out the error in the program?
struct emp
{
    int ecode;
    struct emp *e;
};
Error: in structure declaration
Linker Error
No Error
None of above
Answer: Option
Explanation:
This type of declaration is called as self-referential structure. Here *e is pointer to a struct emp.
Discussion:
11 comments Page 1 of 2.

Nani said:   5 years ago
Is it is endless loop?
(1)

Primshapradheep said:   7 years ago
No error because here e is a pointer, we know the size of a pointer is 4 byte. So no problem, If it's like struct emo e then it will be an error.

Sindhu said:   10 years ago
As said before by some people, here struct emp*e is a self referential pointer.

i.e struct has 2 members, one is int and other one is a pointer which points to the same structure.

Say if any variable is declared.

Ex: struct emp x;
struct emp y;

x's members are ecode and a pointer e which is equivalent to struct emp *e;

e = &x;

Shivam said:   10 years ago
Sorry but can you explain in briefly?

Sruthi said:   1 decade ago
What is nested?

Nani said:   1 decade ago
Struct is a keyword, emp is tag name and *e is a pointer pointing to same strcture.

Bhawna said:   1 decade ago
Can anyone explain in brief the meaning of struct emp *e; ?

Balaraju said:   1 decade ago
Structure can declare nested but is it possible within structure in pointer will occupy.

PSP said:   1 decade ago
Link listed? what does it mean?

Rupinderjit said:   1 decade ago
You are wrong, structure can be nested! And moreover above is the Link listed technique not a nested structure.


Post your comments here:

Your comments will be displayed after verification.