1. Home
  2. Computer Science MCQs
  3. C Programming
  4. After char c = 'A'; c = c + 2; what character does c hold…

Added 30 Nov -0001

After char c = 'A'; c = c + 2; what character does c hold in the ASCII character set?

  1. 'D', because the second letter position is skipped
  2. 'C', because letters have consecutive codes Correct answer
  3. 65, because the value stays numeric
  4. 'B', because incrementing adds one

Correct answer

B. 'C', because letters have consecutive codes

13 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs