I am confused about the output of the following code.
#include
#include
using namespace std;
int main()
{
int a[] = {1,2,3};
An array is not a pointer, but an array decays to a pointer when you try to use it like one. In your case printing the address of the array automatically converts it into a pointer.
There's little difference between the automatically converted pointer and the one created explicitly with &
, except that one is a pointer to a single element while the other is a pointer to the entire array. If you had used &a[0]
then they would be identical.