Q: What will be the output of following code : #includeint main() { if(sizeof(0)) printf(“Hai”); else printf(“Bye”); return 0; }
Solution: sizeof(0) is 4 hence it is true, Hai will be printed as the message.
Q: What will be the output of following code : #includeint main() { if(sizeof(‘ ’)) printf(“inside if block”); else printf(“inside else block”); return 0; }
Solution: A is correct as sizeof(‘ ’) will return 1, hence if condition is true.
Q: What will be the output of following code : #includeint main() { int i = 65; switch(i) { case 65: printf(“Integer 65”); break; case ‘A’: printf(“Char 65”); break; default: printf(“Bye”); } return 0; }
Solution: D is correct as case ‘A’ and case 65 both are same thing and cases can not have duplicate values.
Q: What will be the output of following code : #includeint main() { switch(2/3) { case 1: printf(“case 1 executed “); case 2: printf(“case 2 executed “); break; default: printf(“Default block executed”); } return 0; }
Solution: C is correct as none of the above cases follow the condition so default block will be executed.
Q: What will be the output of following code : #includeint main() { int i = 1; switch(i) { case i: printf(“case 1 executed”); break; case i + 1; printf(“case 2 executed”); break; default: printf(“default block executed”); break; } return 0; }
Solution: Above code will produce error: the value of ‘i’ is not usable in a constant expression.
Q: What will be the output of following code : #includeint main(){ while(printf(“%d”, 5) < 4) printf(“Loop “); return 0; }
Solution: Above code will result in an infinite loop as condition will always be true.
Q: What will be the output of following code : #include#define NULL 0 int main() { while (NULL == 0) { printf(“Loop”); break; } return 0; }
Solution: Null is equivalent to 0. And hence, Option A is correct.
Q: What will be the output of following code : #includeint main(){ float ft = 7.5; while(ft) { printf(“Loop”); ft = ft – .5; if(ft == 5.0f) break; } return 0; }
Solution: while loop will run for 5 times, i.e for the values 7.5, 7.0, 6.5, 6.0, 5,5. Hence, printing “Loop” for 5 times.
Q: What will be the output of following code : #includeint main() { while(!!7) printf(“Hai”); return 0; }
Solution: Above code will result in infinite loop.
Q: What will be the output of following code : #includeint main(){ while(!printf(“awesome”)); return 0; }
Solution: Above code will just print “awesome” as the message.
| You Have Score    | /10 |