What will be the output of the following code ?#include<stdio.h>int main(){char c='A';switch(c){case 64+1: printf("hello ");break;case 8*8+4: printf("world ");break;default: printf("myworld");}printf("welcome");}
Question
What will be the output of the following code ?#include<stdio.h>int main(){char c='A';switch(c){case 64+1: printf("hello ");break;case 8*8+4: printf("world ");break;default: printf("myworld");}printf("welcome");}
Solution
The output of the code will be "hello welcome".
Here's the step by step explanation:
-
The character 'A' is assigned to the variable 'c'. The ASCII value of 'A' is 65.
-
In the switch statement, the expression 64+1 equals 65, which matches the ASCII value of 'c'.
-
Therefore, the program enters the case 64+1 and prints "hello ".
-
After printing "hello ", the break statement terminates the switch and the program jumps to the next line after the switch block.
-
The program then prints "welcome".
-
So, the final output is "hello welcome".
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.