4 ms·
It's worth mentioning explicitly that while `c - 'a'` is the more obvious application of character addition in your example, `c >= 'a'` is another one that's ev
by thaumasiotes 7y ago
It's worth mentioning explicitly that while `c - 'a'` is the more obvious application of character addition in your example, `c >= 'a'` is another one that's even more common. Pretty much everyone immediately understands that we want to be able to sort characters.
- XMPPwocky 7y agoYeah- but the problem of poorly-defined result type isn't present for comparison operators, since a bool is a b... oh, hold on, C. Since an int is an int. Sigh.
- slavik81 7y agoIn C, 'a' is an int so most of those are not char/char operations. In C++, 'a' is a char and the comparison result is a bool, though it doesn't really make a difference in that function.
- thaumasiotes 7y agoWhen you're sorting, you're generally comparing two variables to each other, as opposed to comparing one variable to a literal constant.