+ 4
C question based on switch
Why is the output of the code below "abc" ? Does the switch take the case before default always, if a variable is not specifed? switch(printf("ab")){ case 1:printf("b"); break; case 2: printf("c); break; default:printf("z"); }
7 odpowiedzi
+ 6
Actually the 2 characters printed are 'a' and 'b'. Result of printf is 2 (number of characters output) and inside the switch a 'c' is also printed.
+ 6
\0 is not printed.
+ 3
because "a" contains two characters, 'a' and '\0', and printf returns the number of bytes printed, so it executes case 2.
+ 2
Yes, but Bebida told it as a and \0, as I had previously missed a 'b' in the code😅
+ 2
the output is automatically abc because of the above reason
+ 1
printf("ab") is equal to 2
so that the value c is displayed
0
It is correct