pointer question

Discussion in 'OT Technology' started by D1G1T4L, May 15, 2005.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    whats the difference between

    *ptr, &ptr, and ptr

    *ptr i understand references the actual value of some location
    &ptr gets the address of that location
    what does ptr do?
     
  2. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    ptr is the variable name.
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    ptr stores the address.
    &var obtains the address of var.

    int var = 10;
    int *ptr = &var; // get the address of var and store it in ptr
    *ptr += 2; // take whatever is stored at the address contained in ptr and add 2 to it

    cout << *ptr << endl; // prints 12
    cout << var << endl; // prints 12
    cout << ptr << endl; // prints the address stored in ptr (MS VC++ prints address in hex)
     

Share This Page