3 votes 3 votes No. of times '*' will be printed by the following C code is _____ #include<stdio.h> void foo(int x) { switch(x){ case 1: printf("*"); case 2: printf("*"); case 3: printf("*"); default: printf("*"); } } int main() { foo(2.5); } Programming in C go-programming-1 programming programming-in-c switch-case numerical-answers + – Arjun asked Oct 18, 2016 Arjun 1.2k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 5 votes 5 votes foo(2.5); foo(2) // converting 2.5 into int now case 2 is true so it will print *. case 3 will also print * because no break statement. default case will also print *. TOtal 3 time * will be printed. Digvijay Pandey answered Oct 20, 2016 selected Oct 20, 2016 by Arjun Digvijay Pandey comment Share Follow See all 4 Comments See all 4 4 Comments reply Hemant Parihar commented Oct 28, 2017 reply Follow Share @arjun sir, What if we have 2.99, it is still converting to 2, not 3. 1 votes 1 votes Anu007 commented Oct 28, 2017 reply Follow Share 2.99 stored in integer variable. so it will trancate part after decimal point i.e. if .99999 will be given it will take it as 2 only. 0 votes 0 votes joshi_nitish commented Oct 28, 2017 reply Follow Share by default, when fractional(double) value are converted to int they are implicitly converted using floor(n) function..so no matter if you write 2.001 or 2.999 both will be converted to 2 4 votes 4 votes Anu007 commented Oct 28, 2017 reply Follow Share ...... 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes x=2.5 after converting int x will 2 so * is prited 3 times (one for case 2 ,one for case 3 because no break statement is used here and one for default). SHIVAM GARG answered Aug 19, 2018 SHIVAM GARG comment Share Follow See all 0 reply Please log in or register to add a comment.