Does the unary + operator have any practical use?

char ch="a";
std::cout << ch << '\n';
std::cout << +ch << '\n';

The first insertion writes the character a to cout. The second insertion writes the numeric value of ch to cout. But that’s a bit obscure; it relies on the compiler applying integral promotions for the + operator.

Leave a Comment