After char c = 'A'; c = c + 2; what character does c hold in the ASCII character set?
Correct answer
B. 'C', because letters have consecutive codes
13 views
B. 'C', because letters have consecutive codes
13 views
C stores a char as a small integer, so arithmetic on 'A' (code 65) adds 2 to give 67, which is 'C'. In ASCII the uppercase letters occupy consecutive codes, which is what makes idioms like c - 'a' + 'A' work for case conversion. The result is assigned back to a char, so printf with %c shows the letter while %d would show 67.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.