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 _____. Programming in C tbb-programming-2 numerical-answers + – Bikram asked May 14, 2017 edited Aug 19, 2019 by Counsellor Bikram 351 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 1 votes 1 votes In line number 4, case 1.5 is invalid,the value in case statement is always integer. Bikram answered May 14, 2017 selected Aug 19, 2019 by Bikram Bikram comment Share Follow See all 3 Comments See all 3 3 Comments reply Shaik Masthan commented May 12, 2018 reply Follow Share 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"); } } 3 votes 3 votes val_pro20 commented Jan 6, 2019 reply Follow Share @Shaik Masthan so only float will never allowed? 0 votes 0 votes Shaik Masthan commented Jan 6, 2019 reply Follow Share Float or double or variables etc can't allowed. Which I mentioned are Only allowed 1 votes 1 votes Please log in or register to add a comment.