13,980 views
6 votes
6 votes
structure may contain  
a) any other structure

b) any other structure expect themselves

c) any other structure except themselves and pointed to themselves

d) none of the above

2 Answers

Best answer
4 votes
4 votes

Answer is B.

A) Structures can definitely contain other structures. See chapter 6 in the book on C programming by Dennis Ritchie.

struct rect {
    struct point pt1;
    struct point pt2;
} ;

C) We can have structures which point to them, and we use these a lot when we create linked list. Example:-

struct Node
{
    int data;
    struct Node *next;
};

Here next is a pointer to structure Node.

B)But we cannot have structures which contain themselves. This will give you compile time errors. For example:-

struct regression {
   int int_member;
   struct regression self_member;
};

In order to compile a statement of this type, your computer would theoretically need an infinite amount of memory. In practice, however, you will simply receive an error message along the following lines:

 struct5.c: In function `main':
 struct5.c:8: field `self_member' has incomplete type

The compiler is telling you that self_member has been declared before its data type, regression has been fully declared -- naturally, since you're declaring self_member in the middle of declaring its own data type!

See this: https://stackoverflow.com/questions/588623/self-referential-struct-definition

and this: https://stackoverflow.com/questions/16741618/why-cant-a-struct-have-a-member-that-is-of-the-same-type-as-itself

this one too: http://www.asic-world.com/scripting/structs_c.html

selected by
0 votes
0 votes
Option B) is correct option structure cannot be used in itself...if we do so complation error will come instead we can use any other structure.....

Related questions

0 votes
0 votes
1 answer
1
deepak_8404 asked Oct 1, 2023
295 views
Consider a lower triangular matrix stored in row major order as p[-25 - - + 749][-25 - - - + 749] with base address = 6800, size of each element = 6 byte. Find the value ...
0 votes
0 votes
1 answer
2
jugnu1337 asked May 16, 2023
926 views
The total number of binary trees possible with height n - 2 having n nodes are?(2n - 5)^ 2n - 3 (2n - 7)^2n - 3(n - 3) ^2n - 2(2n - 7)^ 2n - 2
–4 votes
–4 votes
2 answers
4
Souvik33 asked Oct 27, 2022
650 views
*MSQ*The following figure depicts a a. A tree and only treeb. A tree with 3 nodesc. A graph (Since every tree is a graph)d. A graph and only graph