C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Point Out Correct Statements (Q.No. 4)
4.
Which of the structure is incorrcet?
1 :
struct aa
{
    int a;
    float b;
};
2 :
struct aa
{
    int a;
    float b;
    struct aa var;
};
3 :
struct aa
{
    int a;
    float b;
    struct aa *var;
};
1
2
3
1, 2, 3
Answer: Option
Explanation:

Option B gives "Undefined structure in 'aa'" error.

Discussion:
29 comments Page 3 of 3.

Vinod kumar said:   1 decade ago
In this prob. We couldn't create a same structure type within that structure. It will make linking error.

Hariom said:   1 decade ago
Can you please explain more in this question?

Sundar said:   1 decade ago
Option 2, it can be used for creating linked list. A node should have have a link to next node of same type. For this purpose pointer to the same struct (type) is required.

Sampavi said:   1 decade ago
I can't understand. Give briefy explaination.

Sandeep said:   1 decade ago
Option B is declaring a structure variable of the same type in the same structure where as option C is declaring a pointer to the structure variable of the same type. (used in linked lists. ).

B is not allowed as the structure variable declaration can't be done until the structure is declared.

Mani said:   1 decade ago
Why it is incorrect please incorrect?

Kirti said:   1 decade ago
Why B is wrong and C is correct? Please explain.

Rashmi said:   1 decade ago
Why B is wrong and C is correct? Please explain.

Arulrexin said:   1 decade ago
If we can see that program is that second time used stuct variable with using pointer.


Post your comments here:

Your comments will be displayed after verification.