suppose we have an array A[m] [n]. I have found that A=A[0]. If both of the terms contains address only then why not *A and *A[0] gives same results?
Assume that first element is 2 and it's Base address is 1000 then if both A and A[0] contains 1000 then dereferencing of both the terms should yield the same result that is 2.
Add a comment
|
1 Answer
A is not equal to A[0], but A=&A[0][0], i.e, A is a pointer to the first element of the matrix. A[0] is a pointer to A[0][0].
So:
*Agives the address ofA[0];*(A[0])gives 2;*(*A)gives 2;
For instance:
#include <iostream>
int main() {
int A[5][5];
A[0][0] = 2;
std::cout<< *A << std::endl;
std::cout<< *(*A) << std::endl;
std::cout<< *(A[0]) << std::endl;
return 0;
}
This code prints:
0x7fffc5a6fc70
2
2