nested structures

i was asked to find the output of the code
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<stdio.h>
main()
{ struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}

well i was able to give the answer correctly...ie it has an error...but my explanation for supporting my answer was not correct...
i gave my explanation as
Explanation:
cannot use struct xx before defining it completely..

whereas correct explanation is given as
Explanation:
in the end of nested structure yy a member have to be declared.

can anyone explain me the correct explanation and flaw in what i said...
Last edited on
First of all the code outputs nothing. There is no any output operator in the code.
Secondly definitions of the both structure, outer and inner, are correct. So the code shall be compiled.
The only error is that function main shall have return type int specified explicitly.:)
Last edited on
The only error is that function main shall have return type int specified explicitly.


This isn't an error. As of C++98 (I think) the standard has had an implicit return from main if one isn't explicitly written.
@ResidentBiscuit

This isn't an error. As of C++98 (I think) the standard has had an implicit return from main if one isn't explicitly written.


Could you say what is the year now? And what is the current C++ Standard? And what C++ Standard was before the current?






can anyone please explain me the nested structure....is this something like a recursion structure???
A member of a structure can be an object or a type definition of any type.
Last edited on
Could you say what is the year now? And what is the current C++ Standard? And what C++ Standard was before the current?


So I state where you may be wrong, and you turn around by questioning my intelligence? Alright then. ASFAIK, the implicit return has never been taken out of the standard.
@ResidentBiscuit
Alright then. ASFAIK, the implicit return has never been taken out of the standard.


It is very bad when you know nothing but are trying to argue. Please before to state something read the C++ standard.

3.6.1 Main function
This function shall not be overloaded. It shall have a return type of type int


7 Declarations
9 Only in function declarations for constructors, destructors, and type conversions can the decl-specifier-seq be omitted.89


And read attentively what I wrote:

The only error is that function main shall have return type int specified explicitly.
Last edited on
Ah see there's the issue. I thought you were saying you must explicitly write the return statement (as OP did not do this), not the return type of the function itself. If you would have actually read my original post, you would have seen this miscommunication and not made a big deal of it.
Topic archived. No new replies allowed.