Thread: Pointer-to-structure

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    147

    Pointer-to-structure

    Could someone explain to me what does this sign mean :

    "->", i've heard that it is a po inter to structure sign...

    When should I use this, and what does it achieve for me?
    Only by the cross are you saved...

  2. #2
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    If you have a pointer to structure, you can use that arrow operator to point to that structure member.

    Say you have a structure named blah and a pointer to stucture named ptrStruct which has already been assigned, you can do this to access that structures members.
    Code:
    struct blah {
    	int blah1;
    	int blah2;
    	int blah3;
    }
    
    ptrStruct->blah1 = 50;
    
    printf("%d", ptrStruct->blah3);
    Last edited by stumon; 06-06-2003 at 11:05 PM.
    The keyboard is the standard device used to cause computer errors!

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    If you have a structure called employee, you reference an element in the structure like this:
    employee.salary
    This references the structure directly

    But if the employee is a pointer to the structure, you use:
    employee->salary
    This references the structure thru a pointer to the structure


    Ya beat me, stumon!
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    lol, by like 23 minutes. ;D
    The keyboard is the standard device used to cause computer errors!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. method returning a pointer to a structure
    By nacho4d in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2009, 10:01 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. how to cast a char *mystring to a structure pointer ??
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2004, 08:59 AM
  4. Pointer to a structure
    By frenchfry164 in forum C Programming
    Replies: 5
    Last Post: 03-16-2002, 06:35 PM
  5. Pointer to structure problem
    By unregistered in forum C Programming
    Replies: 3
    Last Post: 12-24-2001, 07:54 AM