3 ms·
You showed an example of subtracting a character from another. The GP asked for an example of adding two characters.
by kccqzy 7y ago
You showed an example of subtracting a character from another. The GP asked for an example of adding two characters.
- tlb 7y ago(c - 'a') + 'A' contains both
- XMPPwocky 7y agoI thought about saying (c + 'A') - 'a' to make this more clear, but I think that's actually UB with signed chars- e.g. for c='a', 'a'+'A' exceeds the range of a signed 8-bit value! Promotion should save us here, but that's a bit too yikes-y for my comfort.
- kccqzy 7y agoIt does not. Subtracting a char from a char involves usual arithmetic conversions as well and the result is typically an int. Next, you have addition between an int and a char.
- deleted 7y ago[deleted]