How do pointers in C++ work

Discussion in 'Programming' started by sai_sidd, Jul 31, 2008.

  1. #1
    i need an example
     
    sai_sidd, Jul 31, 2008 IP
  2. Typo3 Steve

    Typo3 Steve Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Let's say you have this variable:

    int i_value = 50;

    The value of a pointer is a memory address, where its real value really is. Take it like a bridge that goes to a big value.

    This makes a pointer to the value above:

    int *i_pointer = &i_value;

    The value of i_pointer is a memory address, but if you get the value where i_pointer points, you willget 50. If you change the i_value variable value, the value of where i_pointer points willalso change.

    So, if you do that:

    i_value = 77;

    The value where i_pointer points is also 77.

    Pointers are normally used to point to big objects or structures. That way, the variables (objects, structs, etc.) that really uses a lot of memory are not duplicated. This uses a lot less memory.

    If you have any question, just asks them...Ill bookmark this thread now.

    Steve
     
    Typo3 Steve, Jul 31, 2008 IP