W
Wajih-ur-Rehman
The question is about C++ (since its the C family, i posted it on this
newsgroup)
Lets say i declare an array
int a[] = {1,2,3,4};
int *p = a; //This is allowed because "a" returns the address of the first
element
The question is actually about 2D arrays. As far as I know, when a 2D array
is declared in C++, in the memory it is actually stored as a 1D array. and
the name of the array is pointing to the first element ie. a[0][0] i.e
int a[2][2] = { {1,2},{3,4} };
Now the question is that why cant i do this
int *p = a; //Compiler gives error. Whats wrong with this????? a is not an
int ** right?
However following are correct
int *p = &a[0];
int *p = &a[0][0];
Why doesnt int* p = a; work? (if you cout<<a<<&a[0]<<&a[0][0]; it gives the
same address)
Thanx in advance
newsgroup)
Lets say i declare an array
int a[] = {1,2,3,4};
int *p = a; //This is allowed because "a" returns the address of the first
element
The question is actually about 2D arrays. As far as I know, when a 2D array
is declared in C++, in the memory it is actually stored as a 1D array. and
the name of the array is pointing to the first element ie. a[0][0] i.e
int a[2][2] = { {1,2},{3,4} };
Now the question is that why cant i do this
int *p = a; //Compiler gives error. Whats wrong with this????? a is not an
int ** right?
However following are correct
int *p = &a[0];
int *p = &a[0][0];
Why doesnt int* p = a; work? (if you cout<<a<<&a[0]<<&a[0][0]; it gives the
same address)
Thanx in advance