Difference between `a` and `&a` in C++ where `a` is an array -


i confused output of following code.

#include<iostream> #include<cstdlib> using namespace std; int main() {   int a[] = {1,2,3};   cout <<         << "  " << &a         << endl;   cout << sizeof(a) << "  " << sizeof(&a) << endl;   return 0; } 

the output

0xbfcd3ae4  0xbfcd3ae4 12  4 

how can a , &a print same expression have different sizes? thought array, name has value = address of first byte.

also &a should not make sense, since 1 cannot have address (obtained & operator) address(the value of a). yet code gives output , infact 'a == &a' according output.

similarly why output of sizeof(a) = 12 (which total memory occupied) array? a being "pointer" sizeof(a) = 4 bytes (on 32 bit ubuntu 11.04)

obviously there misconception having. 1 sort out me ?

an array not pointer, array decays to pointer when try use one. in case printing address of array automatically converts pointer.

there's little difference between automatically converted pointer , 1 created explicitly &, except 1 pointer single element while other pointer entire array. if had used &a[0] identical.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -