You have two separate questions here.
-
A pointer is sometimes used to point to an array or buffer in memory. Therefore it supports the
[]
syntax. In this case, usingpi[x]
where x is not 0 is invalid as you are not pointing to an array or buffer. -
Streams have an overload for
char
pointers to treat them as a C-style string, and not output their address. That is what is happening in your second case. Trystd::cout << static_cast<const void *>(&(c[3])) << endl;
solved two short questions about pointers and references