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 : |
|
2 : |
|
3 : |
|
Answer: Option
Explanation:
Option B gives "Undefined structure in 'aa'" error.
Discussion:
29 comments Page 1 of 3.
Rashmi said:
5 years ago
Anyone please explain the right answer.
(1)
Aman Saxena said:
6 years ago
According to me the, best possible reason can be:
Structure is a user-defined data type, so when we declare any variable using that data type, that var get the size of that datatype.
Now here in structure 2, we have declared the strct type variable, before the complete declaration of struct, hence it gives the error.
But in structure 3, we can define a pointer of the same type, as it is fixed that any pointer will always take a space of 4 bytes.
Structure is a user-defined data type, so when we declare any variable using that data type, that var get the size of that datatype.
Now here in structure 2, we have declared the strct type variable, before the complete declaration of struct, hence it gives the error.
But in structure 3, we can define a pointer of the same type, as it is fixed that any pointer will always take a space of 4 bytes.
(5)
Suraj said:
7 years ago
B. is incorrect because there is no declaration of struct aa;
But in c there is pointer *aa so it can declare it self as a garbage value.
But in c there is pointer *aa so it can declare it self as a garbage value.
(1)
C.kumar said:
7 years ago
Thank you @Jarvis.
Sakthi said:
7 years ago
Shall I declare struct aa var; outside the structure? Can Anyone explain, please?
Prashant said:
7 years ago
You can not put a whole struct inside of itself because it would be infinitely recursive.
But you can put the address of another instance of a struct inside of a struct; which is what a pointer is. An address the size of SomeStruct* is always the same, so the compiler knows how much memory to make for one instance of the struct.
But you can put the address of another instance of a struct inside of a struct; which is what a pointer is. An address the size of SomeStruct* is always the same, so the compiler knows how much memory to make for one instance of the struct.
(1)
Bindu said:
8 years ago
Please explain briefly I can't understand.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers