1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Which type may a switch statement's controlling expression…

Added 30 Nov -0001

Which type may a switch statement's controlling expression NOT have in C?

  1. A floating-point type such as double, which has no integer promotions Correct answer
  2. An unsigned long long, because the case labels would overflow int
  3. A plain char, because its signedness is implementation-defined in C
  4. An enumerated type, because its enumerators are not integer constants

Correct answer

A. A floating-point type such as double, which has no integer promotions

24 views

MCQSEXAM

Explanation

The switch controlling expression must have integer type, so a double is rejected outright, while char, enum and unsigned long long are all allowed after integer promotion. Case labels must be integer constant expressions and are converted to the promoted controlling type, which is why an unsigned long long switch is legal. A duplicate case value, or two labels that convert to the same value, is a constraint violation.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

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