1. Home
  2. Computer Science MCQs
  3. C Programming
  4. On a platform with 32-bit int and 32-bit unsigned int…

Added 30 Nov -0001

On a platform with 32-bit int and 32-bit unsigned int, what is the type of the literal 0x80000000?

  1. long, because the value exceeds the range of both int and unsigned int on this target
  2. Undefined, because no signed 32-bit type can represent that particular bit pattern
  3. unsigned int, because hexadecimal literals take the first type in their list that fits Correct answer
  4. int, because hexadecimal constants are signed by default unless a u suffix is supplied

Correct answer

C. unsigned int, because hexadecimal literals take the first type in their list that fits

15 views

MCQSEXAM

Explanation

Unsuffixed hexadecimal constants are considered in the order int, unsigned int, long, unsigned long until one type can represent the value, so 0x80000000 becomes unsigned int on a 32-bit target. The decimal constant 2147483648 instead becomes long, because decimal constants never take an unsigned type unsuffixed. Printing 0x80000000 with %d is therefore technically a type mismatch.

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