Thread: Pointer confusion...

  1. #1

    Question Pointer confusion...

    I wrote some sample code in VC++ .net and it involved pointers. To set the address of the pointer I had to do this:

    Code:
    int *a;
    
    a = 0x00C000;
    and use it like this

    Code:
    int iVal;
    
    iVal = *a;
    I thought using the asterisk in front of the pointer would make it return the address, or you could set the address that way. Wasn't it the other way around in VC++6?

    Wasn't it like this in VC++6:
    Code:
    int *a, iVal;
    
    *a = 0x00C000;
    iVal = a;
    -Mike
    {InFeStEd-ArCh0n}

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I thought using the asterisk in front of the pointer would make it return the address
    Using the asterisk is called dereferencing, and it means that you are returning the contents of the address that the pointer points to:
    Code:
    #include <iostream>
    
    int main ( void )
    {
      int x = 10, 
          *p = &x;
      std::cout<<"x  is "<< x 
               <<"\n*p is "<< *p 
               <<"\np  is "<< p <<"\n";
      return 0;
    }
    I'm not sure what kind of insane changes the .NET framework requires of C++, but it doesn't sound standard to me.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer confusion
    By rohit_second in forum C Programming
    Replies: 1
    Last Post: 10-20-2008, 04:25 AM
  2. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2007, 11:26 PM
  3. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  5. Pointer confusion...
    By fkheng in forum C Programming
    Replies: 13
    Last Post: 06-23-2003, 10:18 PM