0

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.

1 Answer 1

1

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:

  • *A gives the address of A[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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.