Object in structure? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Object in structure?

What do this mean? struct something { int a; something b; } ; What will the object of this structure contains?

23rd Dec 2017, 2:07 PM
Panda
Panda - avatar
4 Answers
+ 9
It's always a good idea to tag the language you are asking a question about
23rd Dec 2017, 2:21 PM
David Akhihiero
David Akhihiero - avatar
+ 7
This structure contains an integer variable, and an instance of itself.
23rd Dec 2017, 2:37 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
The object will not be. This code would not compile for two reasons: 1. There's no "something" defined before the "something" definition is complete. So, even if it were to be forward declared, "something" would've have incomplete type inside the definition. And as the size of it cannot be determined, such structure cannot be defined. 2. Even if this were to be worked around somehow, it would've only led the compiler to the infinite recursion. The structure may contain a pointer to itself though. And it is used quite often. For linked lists, for example.
23rd Dec 2017, 8:39 PM
deFault
+ 2
Part or the section of structure
2nd Jan 2018, 9:23 AM
Boev Dilshod
Boev Dilshod - avatar