[openbeos] Re: Largely Offtopic C/C++ question about pointers
- From: Martin Olsson <mnemo@xxxxxxxxxx>
- To: openbeos@xxxxxxxxxxxxx
- Date: Wed, 27 Jul 2005 22:11:21 -0700
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
- Follow-Ups:
- [openbeos] Re: Largely Offtopic C/C++ question about pointers
- From: Bruno van Dooren
- [openbeos] Re: Largely Offtopic C/C++ question about pointers
- From: Charlie Clark
- References:
- [openbeos] Re: GE [was Re: Tracker icons]
- From: Simon Taylor
- [openbeos] Re: GE [was Re: Tracker icons]
- From: Czeslaw Czapla
- [openbeos] Largely Offtopic C/C++ question about pointers
- From: Bruno van Dooren
Other related posts:
- » [openbeos] Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
- » [openbeos] Re: Largely Offtopic C/C++ question about pointers
First off, I would like to say: that:
//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};
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
sincerly, martin
- [openbeos] Re: Largely Offtopic C/C++ question about pointers
- From: Bruno van Dooren
- [openbeos] Re: Largely Offtopic C/C++ question about pointers
- From: Charlie Clark
- [openbeos] Re: GE [was Re: Tracker icons]
- From: Simon Taylor
- [openbeos] Re: GE [was Re: Tracker icons]
- From: Czeslaw Czapla
- [openbeos] Largely Offtopic C/C++ question about pointers
- From: Bruno van Dooren