Thread: struct address

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    180

    struct address

    Was doing some tests with structs but i don't undertand the code below. Say you have a struct called Student with 3 fields name, number and numUnits and then you make a pointer to it *V.
    Using &V[0] gives me the address of the first one. What does V[0] give? Seems like another address, but for what?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    V[0] represents the first element (the first struct) as opposed to the address of the first element.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    180
    Yeah so what does the number it prints mean? It has no meaning? I tried to printf V[1] too and the number it printed didnt change.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Are you talking about an array of struct? How about you post a simple example of what exactly you're talking about.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help getting the address of a struct member
    By Telomin in forum C Programming
    Replies: 1
    Last Post: 04-17-2015, 06:40 PM
  2. Get address of int within a struct
    By Benji Wiebe in forum C Programming
    Replies: 18
    Last Post: 09-12-2011, 08:14 PM
  3. Replies: 5
    Last Post: 06-30-2011, 03:24 PM
  4. C De-reference + Memory address together in struct?
    By valaris in forum C Programming
    Replies: 6
    Last Post: 06-18-2008, 01:31 AM
  5. address of struct variable?
    By DavidDobson in forum C Programming
    Replies: 2
    Last Post: 06-09-2008, 03:01 AM