C++ Interview Question 2 Answer

Bjarne-stroustrup
 

Answer

This question is compilable and deterministic.

Its output is “22”.

Explanation

A string literal is not a std::string, but a const char[] . If the compiler was to choose f(const std::string&), it would have to go through a user defined conversion and create a temporary std::string. Instead, it prefers f(const void*), which requires no user defined conversion.

SOURCE