171k views
0 votes
Is it legal to use a non-integral value in a case value?

1 Answer

4 votes

Final answer:

In programming, using non-integral values in a case value is typically not allowed because case statements require integral or enumerable case values that are compile-time constants.

Step-by-step explanation:

The question 'Is it legal to use a non-integral value in a case value?' pertains to programming, specifically the use of case statements within switch-case control structures in many programming languages. In general, case statements require integral or enumerable case values (i.e., values that can be evaluated at compile-time as distinct, constant values). Most programming languages, such as C, C++, and Java, do not allow non-integral values such as floats or strings to be used in case labels because these values are not compile-time constants. However, some modern or specialized languages may offer extensions or variations that accept non-integral case values.

User Konrad Neuwirth
by
8.8k points