It's one of those things you either know about C/C++ or you don't know.
if p is a pointer then p[4] means *(p+4) and because the + operator is commutative (spelling) then p+4 is the same as 4+p. So p[4] is the same as 4[p] in array indexing. Note one of the terms must be a pointer.
In the original post, the () around the 4 is not necessary - so it could have been written as cout << 4[p]