1. Home
  2. Computer Science MCQs
  3. C Programming
  4. On a platform where plain char is signed, char c = 200; is…

Added 30 Nov -0001

On a platform where plain char is signed, char c = 200; is followed by int i = c; what is i?

  1. 200, because a char always holds the value assigned to it at initialisation
  2. 56, because the sign bit is cleared during promotion and only the low seven bits survive
  3. -56, because 200 does not fit in a signed 8-bit char and wraps to 200 minus 256 Correct answer
  4. Indeterminate, because the conversion is undefined behaviour the compiler may optimise away

Correct answer

C. -56, because 200 does not fit in a signed 8-bit char and wraps to 200 minus 256

14 views

MCQSEXAM

Explanation

Signed char range is -128 to 127, so converting 200 to signed char is implementation-defined and typically wraps to -56, and the promotion to int preserves that negative value. Using unsigned char or the uint8_t typedef keeps the value at 200 and is the correct choice for raw byte data. This is why byte buffers should not be plain char when values above 127 matter.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? 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