I'm trying to understand pointers and and arrays in C++. I've noticed that in the following code outputting a correctly gives the address of the first element in array, however outputting c gives pk rather than an address.
int array[3]={4,7,2};
int * a;
a= array;
char Carray[3]={'p','k','\0'};
char * c;
c= Carray;
cout << a << "\n";
cout << c << "\n";
Is this the incorrect way to find the address of the first element in Carray? Or is this some quirk of how cout interprets pointers for integer and character arrays.
Output:
Ox23fe30
pk
chararrays ending in a null char\0, andcoutis assuming you are passing it a C-style string. So your method of getting the address of first element is correct, butcout's interpretation of that address is different forintandchar.