What is out put of this program ?

hi CEns
could anyone explain in detail of this code.


#include
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    #-Link-Snipped-# : Why not post an analyses on your own first? Ask others to correct you ๐Ÿ˜€ That'd be a better approach. What say?
  • hare singh nayak
    hare singh nayak
    The_Big_K
    #-Link-Snipped-# : Why not post an analyses on your own first? Ask others to correct you ๐Ÿ˜€ That'd be a better approach. What say?
    actually sir i have tried allot but i am not able to understand..
  • Kaustubh Katdare
    Kaustubh Katdare
    hare singh nayak
    actually sir i have tried allot but i am not able to understand..
    Don't worry about being 'right'. Just go step by step and share your thoughts. That'd be a better way to attack such problems. People will appreciate if you put some efforts and share them with us.
  • Sreejith T
    Sreejith T
    hare singh nayak
    hi CEns
    could anyone explain in detail of this code.


    #include
    main()
    {
    struct xx
    {
    int x;
    struct yy
    {
    char s;
    struct xx *p;
    };
    struct yy *q;
    };
    }
    hey ... have you compiled this program..... ???? i think it has got some incorrect termination error (i compiled it).... itz not executing..... ๐Ÿ˜”
  • hare singh nayak
    hare singh nayak
    Sreejith T
    hey ... have you compiled this program..... ???? i think it has got some incorrect termination error (i compiled it).... itz not executing..... ๐Ÿ˜”
    yea i have compiled this code and there is compilation error but i want to know why compilation error is there and what is wrong in it.
  • David Emperor
    David Emperor
    I want to know, is it a C++ code
    if it is
    you used a function which doesn't return a parameter
    instead of main() you must use void main()
    or int main() and before last } write return 0;
  • Sreejith T
    Sreejith T
    David Emperor
    I want to know, is it a C++ code
    if it is
    you used a function which doesn't return a parameter
    instead of main() you must use void main()
    or int main() and before last } write return 0;
    hey dude, i think itz a C code ๐Ÿ˜€
  • Sreejith T
    Sreejith T
    hare singh nayak
    yea i have compiled this code and there is compilation error but i want to know why compilation error is there and what is wrong in it.
    Hey ... i think u have to declare a structure variable for 'struct xx' and have to point the pointer *p to the structure variable of 'xx' structure .... just check : #-Link-Snipped-#
    prog no. 5.2


    if u declare an object to both the structures xx and yy, then the error message would be cleared ... but the pgm shows no output coz the pointers just point to the structure and nothing else wud happen .... i think it wud work only this manner ... plz consider others also .. coz im only a 2nd year b.tech CSE student .... ๐Ÿ˜€ ๐Ÿ˜‰
  • Priya Nadkarni
    Priya Nadkarni
    Hi,I tried this code out in Borland C++ and it didn't show any error. Its just a concept of nested structure.
  • Banashree Patra
    Banashree Patra
    hare singh nayak
    hi CEns
    could anyone explain in detail of this code.


    #include
    main()
    {
    struct xx
    {
    int x;
    struct yy
    {
    char s;
    struct xx *p;
    };
    struct yy *q;
    };
    }
    Hey @ hare singh nayak if we write the above code as
    #include
    main()
    {
    struct xx
    {
    int x;
    struct yy
    {
    char s;
    struct xx *p;
    }*q;
    };
    }
    then it is not giving any error,though both are same.
  • slashfear
    slashfear
    isn't this a nested struct...? first you have defined an struct named xx then with in that you have defined another struct named yy which has a reference to (pointer) to struct xx...! I believe it should cause an compilation error as the struct xx was not defined at all but used .....

    NOTE: I have not complied the code but answered with my understanding....

    -Arvind
  • Vishal Sharma
    Vishal Sharma
    struct xx was not defined at all but used .....
    what do you mean by defining the struct? Are you telling that the definition must be done globally??
    Well, If you mean that, it doesn't matter if you declare it globally or declare it inside a function (main here) it does the same work. The only difference is, its life is within the block of declaration.
  • Vishal Sharma
    Vishal Sharma
    Banashree Patra
    Hey @ hare singh nayak if we write the above code as
    #include
    main()
    {
    struct xx
    {
    int x;
    struct yy
    {
    char s;
    struct xx *p;
    }*q;
    };
    }
    then it is not giving any error,though both are same.
    How about writing a few more statements and check the answer? i mean declare the struct variables, allow 'em to go through several calculations, check whether you got the desired output or not...

You are reading an archived discussion.

Related Posts

please suggest me some topics for ppt. Should me mechanical related.
This is the most intriguing question i've ever had in my mind(along with some other...)..! So do aliens really exist? One side, there's the phenomenal Stephen Hawking emphasizing that they...
Hey, m juhi.. joint this site coz since few days i've been visiting it daily, M a student of MCA, bt couldnt find that option in the login process.. I...
hello, I am student of M.tech. I want some information about viscoelastic fluid for my project work. Q.1- Is oil a viscoelastic fluid? Q.2- Give me information about the other...
Most of you must be aware that while water, is moved about by centrifugal pumps, (dynamic type), oil is moved about by gear, gerotor, or anyother positive displacement type of...