int a[3]
creats an array inside the functions (po) Stack-Frame -> on the programs stack.
Once the function finished the allocated space is gone (together with the Stack-Frame).
From my understanding: the reason the first element of the Array is "memorised" is because it's the only Element of your array, that even after the function finished still has a pointer to it (p). (the others dont since "a" will be gone)
If you want this to work you have to allocate memory for the array on the heap (where it will stay until you call "delete []"
To do this, initialize the array this way: int * a = newint[3];
that's all (the array Elements are simply stored somewhere else, where they won't be deleted (more precise the memory won't be free'd) when the function returns)
ps: allocating memory on the heap is slower than on the stack - just nice2know ;)