CrazyEngineers
  • What is out put of this program ?

    Updated: Oct 26, 2024
    Views: 1.0K
    hi CEns
    could anyone explain in detail of this code.


    #include<stdio.h>
    main()
    {
    struct xx
    {
    int x;
    struct yy
    {
    char s;
    struct xx *p;
    };
    struct yy *q;
    };
    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorAug 14, 2012

    #-Link-Snipped-# : Why not post an analyses on your own first? Ask others to correct you 😀 That'd be a better approach. What say?
    Are you sure? This action cannot be undone.
    Cancel
  • hare singh nayak

    MemberAug 14, 2012

    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..
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorAug 14, 2012

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Sreejith T

    MemberAug 17, 2012

    hare singh nayak
    hi CEns
    could anyone explain in detail of this code.


    #include<stdio.h>
    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..... 😔
    Are you sure? This action cannot be undone.
    Cancel
  • hare singh nayak

    MemberAug 17, 2012

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • David Emperor

    MemberAug 17, 2012

    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;
    Are you sure? This action cannot be undone.
    Cancel
  • Sreejith T

    MemberAug 18, 2012

    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 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Sreejith T

    MemberAug 18, 2012

    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 .... 😀 😉
    Are you sure? This action cannot be undone.
    Cancel
  • Priya Nadkarni

    MemberAug 28, 2012

    Hi,I tried this code out in Borland C++ and it didn't show any error. Its just a concept of nested structure.
    Are you sure? This action cannot be undone.
    Cancel
  • Banashree Patra

    MemberAug 29, 2012

    hare singh nayak
    hi CEns
    could anyone explain in detail of this code.


    #include<stdio.h>
    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<stdio.h>
    main()
    {
    struct xx
    {
    int x;
    struct yy
    {
    char s;
    struct xx *p;
    }*q;
    };
    }
    then it is not giving any error,though both are same.
    Are you sure? This action cannot be undone.
    Cancel
  • slashfear

    MemberAug 31, 2012

    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
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberAug 31, 2012

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberAug 31, 2012

    Banashree Patra
    Hey @ hare singh nayak if we write the above code as
    #include<stdio.h>
    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...
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register