Thread: help getting the address of a struct member

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    5

    help getting the address of a struct member

    hello, my problem is that i have two structs

    Code:
    struct data{
    
      char data[20];
      struct data *next;
    };
    
    struct node{
    
      struct data *head;
      
    };

    and i have an array of struct node

    Code:
    struct node *array = malloc(10 * sizeof(struct node));
    
    int i;
    for(i = 0; i < 10; i++){
     
    }
    how can i get the address of any of the struct member "*head" of this array? to store it in other var and change it?

    Code:
    struct data **neeew = NULL
    *neeew = &(array+5)->head; //doesnt work

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    You don't want to dereference it, this would do:
    Code:
    neeew = &array[5].head; /* same as &(array+5)->head */
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-30-2011, 03:24 PM
  2. Replies: 3
    Last Post: 05-27-2011, 06:11 PM
  3. Assign struct member value to struct member value
    By thahemp in forum C Programming
    Replies: 5
    Last Post: 10-13-2010, 09:48 AM
  4. Assigning memory address of member struct to pointer.
    By Tronic in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2004, 05:53 PM
  5. address of a member function
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-10-2002, 06:16 AM