pointer to array c++
c++
Solution
`<<` has a dedicated overload for `const char *`, because that's what a C-style string is. Try this:
cout << static_cast<const void *>(bar2) << endl;
Problem
My understanding about assigning an array to a pointer is that the pointer is pointing at the first index of the array, so when printout the pointer, it should print out the address of the first index of the array, but how come in this case the cout printed out the value of the whole array? even though I explicitly indicated that I wanted the address of the first index ``` char foo[] = {'A','B','C','\0'}; char* p = foo; char* q = &(foo[0]); cout <<"from p: " << p << endl; cout << "from q: " << q << " " << &(foo[0]) << endl; //output from p: ABC from q: ABC ABC ``` the second question is that I see the difference between those two lines is that one is an array of pointer to char, the other is a pointer to a char array, is that correct? is the parenthesis necessary? ``` char* bar1[4]; char (*bar2)[4] = &foo; cout << "address of foo is " << bar2 << endl; //output address of foo is 0x7fff192f88b0 ``` The address of the foo array should be the same as the address of A, right? How do I printout the address of A? since I failed to do so. Thank you very much