4 4 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 two-marks + – Arjun 2.3k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 7 7 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 4 4 Comments reply Hemant Parihar commented Oct 28, 2017 reply Follow flag @arjun sir, What if we have 2.99, it is still converting to 2, not 3. 1 1 replyShare Anu007 commented Oct 28, 2017 reply Follow flag 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 0 replyShare joshi_nitish commented Oct 28, 2017 reply Follow flag 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 4 replyShare Anu007 commented Oct 28, 2017 reply Follow flag ...... 0 0 replyShare Please log in or register to add a comment.
0 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 0 reply Please log in or register to add a comment.