-> operator

This is a discussion on -> operator within the C Programming forums, part of the General Programming Boards category; what does -> mean in a c or c++ program?...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    110

    -> operator

    what does -> mean in a c or c++ program?
    PHI is one 'H' of alot more interesting than PI!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    if we have a pointer to struct:
    Code:
    struct x 
    { 
       int a;
       int b;
    };
    
    struct x *px;
    ...
    // code assigns valid address to px. 
    ...
    then we can access the contents of the struct this way:
    Code:
       (*px).a = 7;
       (*px).b = 9;
    But that's quite awkward to write (it gets even worse if you have a struct with pointers to structs in it).
    So the language also has a short form of this:
    Code:
       px->a = 7;
       px->b = 9l
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Makes sense. Thanks alot.
    PHI is one 'H' of alot more interesting than PI!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Overloading -> operator
    By Hunter2 in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2004, 03:08 PM
  4. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM
  5. -> operator and its uses and benefits
    By supaben34 in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2002, 02:56 AM

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