structure of structure

This is a discussion on structure of structure within the C Programming forums, part of the General Programming Boards category; Hi... how I can create a structure that pointing to another different structure. And also passing structure to function. thank ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    32

    structure of structure

    Hi...
    how I can create a structure that pointing to another different structure. And also passing structure to function.



    thank you.

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    struct x {
        int a;
    };
    
    struct y { 
        struct x * z; 
    } s;
    
    void foo(struct y bar) {
    
    }
    
    int main() {
        foo(s );
    }
    Kurt

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    32
    Hi...Zuk
    could you give an explanation for the above ...

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    struct x {
        int a;
    };
     
    struct y {  // defines a struct that contains a member that points to another struct
        struct x * z;
    } s;    // s is an instance of a struct y
     
    void foo(struct y bar) {  // a function that takes a struct y as parmeter
     
    }
     
    int main() {
        foo( s ); // call a function that takes a struct as parameter
    }
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to find number of structure members in a given structure?
    By bhaskarReddy in forum C Programming
    Replies: 4
    Last Post: 01-16-2012, 04:37 AM
  2. Replies: 4
    Last Post: 04-25-2010, 10:57 AM
  3. Replies: 1
    Last Post: 04-02-2009, 06:51 AM
  4. Replies: 9
    Last Post: 05-21-2007, 12:10 AM
  5. Replies: 4
    Last Post: 11-22-2006, 11:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21