Fill This Form To Receive Instant Help
Homework answers / question archive / Do you think that the following C code will compile? Do you think that the following C code will compile? Why or why not? What will be printed by it? char c; c = '1'; switch (c) { case 1 : printf("It is 1n"); break; case 2 : printf("It is 2n"); break; case 49: printf("It is 49n"); }
Do you think that the following C code will compile?
Do you think that the following C code will compile? Why or why not? What will be printed by it?
char c;
c = '1';
switch (c)
{
case 1 : printf("It is 1n");
break;
case 2 : printf("It is 2n");
break;
case 49: printf("It is 49n");
}
Yes, the code will compile (assuming that this piece of code is written in main() function) as there are no syntax errors and semantic errors. Since the character variable c is assigned with the character constant '1', but when passed to the switch statement, it will be interpreted as ASCII value of the corresponding character constant and in this case ASCII value for '1' is 49. Hence, the output of this code will be "It is 49".