Address of Pointer_variable of Integer



  • #include <iostream>
    
    using namespace ::std;
    
    int main(int argc, char* argv[])
    {
      int var[] = {20,40,20};
      cout <<var <<" " <<&var;
    }
    

    OutPut:
    0x7fff7312b560 0x7fff7312b560

    my Question is:
    Why do i get the same address ? is var[] a pointer_variable? If yes, how can i see the address of this Pointer_variable ?

    thank you for any single tips.
    regards
    Buddy



  • I cannot compile this with my C compiler, I wonder why... 😕

    var behaves like a pointer but it is an array stored at the address &var . In the case std::cout << var it is implicitly casted to a pointer that points to the start of the array, hence its the same value as &var and even &(var[0]) .

    btw: C++ question do not belong in the ANSI C Forum.



  • thanks for the reply.
    Superb explained.

    regards
    Buddy


Anmelden zum Antworten