[openbeos] Re: Largely Offtopic C/C++ question about pointers


First off, I would like to say: that:

   This is why Java and .NET was created! =)


Bruno van Dooren wrote:
//example 1:
typedef int t_Array[10];
int main(int argc, char* argv[])
{
 t_Array array;
 array[0] = 123;
 array[9] = 321;

t_Array *ptrArray[] = {&array};

In C/C++ arrays are essentially pointers to the first array element. That is array is a pointer, and thus &array is the address of another pointer which in turn points to the first element.


t_Array *element = ptrArray[0];

So ptrArray[0] == &array is a pointer to a pointer to 123.

 printf("array = 0x%08x, ptrArray[0] = 0x%08x, element = 0x%08x, *element =
0x%08x\n",
   array, ptrArray[0], element, *element);

To be honest, I was expecting array=SOMETHING, ptrArray[0]=SOMETHING_ELSE

So, basically I'm just as confused as you are, if not more. Given that I've only written a single C++ program in my entire life, maybe I should leave this one to someone else! :)


sincerly, martin

Other related posts: