switch case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

switch case

why in this switch case the program executes the third case ??! cause we have 3 characters (h i -)?? switch (printf("hi-")) { case 1: printf ("a"); break; case 2: printf ("b"); break; case 3: printf ("c"); break; default: printf ("default"); } //result hi-c

7th Feb 2020, 6:37 AM
{ SorousH }
{ SorousH } - avatar
1 Answer
+ 2
Yes, that seems to be true: https://code.sololearn.com/cO73iv1EZ16s/?ref=app That might be because the printf is a function which actually writes text to a file, which will be used by command prompt to display data on the screen. In Python you can write data to a file using write method and the written amount of characters will be returned as an integer. Because printf also actually writes data to a file it could also return the amount of written characters.
7th Feb 2020, 7:23 AM
Seb TheS
Seb TheS - avatar