Pointer confusion...

This is a discussion on Pointer confusion... within the C++ Programming forums, part of the General Programming Boards category; I wrote some sample code in VC++ .net and it involved pointers. To set the address of the pointer I ...

  1. #1
    Registered User InFeStEd-ArCh0n's Avatar
    Join Date
    Apr 2002
    Posts
    63

    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,796
    >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, 01:19 AM
  5. Pointer confusion...
    By fkheng in forum C Programming
    Replies: 13
    Last Post: 06-23-2003, 10:18 PM

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