in Programming edited by
214 views
0 votes
0 votes

Spot the error(s) in this code snippet :

int n=2;   // Line 1
switch(n)
{
case 1.5:
printf( "gate");
break;
case 2:
printf( "overflow");
break;
case 'A':
printf("gateoverflow");
}         // Line 12

The error(s) is in line number _____.

in Programming edited by
by
214 views

1 Answer

1 vote
1 vote
Best answer
In line number 4, case 1.5 is invalid,the value in case statement is always integer.
selected by

3 Comments

No need to integer it can be integral type (int,char,enum) which should be evaluated at compile-time.

#include <stdio.h>
int main()
{
        enum day {sun=5,mon,tue};
        enum day today=sun;
    int n=7;   // Line 1
    switch(n)
    {
        case (sizeof(int)):
            printf( "gate");
            break;
        case 'j':
            printf( "over");
            break;
        case tue:
            printf("flow");
    }   
}
2
2

@Shaik Masthan so only float will never allowed?

0
0
Float or double or variables etc can't allowed.

Which I mentioned are Only allowed
1
1
Answer:

Related questions