"ab"
is a string literal of type const char [3]
and it decays to a const char*
due to type decay when used in the expression "ab" + 'a'
.
+
is an arithmetic operator and so the character literal 'a'
is promoted to an int
.
Thus essentially, you're doing pointer arithmetic. In particular, you're adding the promoted int
value to the decayed const char*
. Since std::ostream
has an overloaded operator<<
:
template< class Traits >
basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os,
const char* s );
It will be used. That is, the argument to the parameter named s
will be the result of adding the promoted int
value to the decayed const char*
.