You cannot dereference an array, only a pointer.
What's happening here is that an expression of array type, in most contexts, is implicitly converted to ("decays" to) a pointer to the first element of the array object. So ar
"decays" to &ar[0]
; dereferencing that gives you the value of ar[0]
, which is an int
.
This recent answer of mine discusses this in some detail for C. The rules for C++ are similar, but C++ has a few more cases where the conversion does not occur (none of which happen in your code).