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 2 of 3.

Sandeep Reddy said:   8 years ago
Because pointer and structure are same data types (user defined).

Vrushali kute said:   8 years ago
I think C is the correct answer.

Md kamal said:   8 years ago
I am not understanding this. Please, anyone explain this.

Bhanu prataap said:   9 years ago
I can't understand please give me the deep description why the answer is B?

Kushal baldev said:   9 years ago
First declaration of the structure is done after that only you can declare the variable as the structure is mix collection of data types so if one doesn't know the size how can we declare a variable? Where as a pointer size is a fix of two bytes in the general scenario?

Harsha said:   1 decade ago
Why it gives such error? Give clear explanation.

Seema said:   1 decade ago
*var is the pointer variable of structure & var is variable of structre which cannot be created before creation of structre.

Rajesh said:   1 decade ago
struct aa var; - It is incorrect because we don't know the size of structure... before that only we declaring.

structure aa *var means pointer to structure itself... that is allowed.

Mosin said:   1 decade ago
Give diff b/w struct aa var and struct aa *var.

Abhisha said:   1 decade ago
We can create only a pointer of the structure an the same struct but struct <struct_name> <object>; is syntax for creating a reference to that struct. In this case struct x is not aa is not yet created. So 2nd is wrong.


Post your comments here:

Your comments will be displayed after verification.