Which type may a switch statement's controlling expression NOT have in C?
Correct answer
A. A floating-point type such as double, which has no integer promotions
24 views
A. A floating-point type such as double, which has no integer promotions
24 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.