C Control Statements Test 4C control statements test paper 4 contains questions from decision statement: if-else and switch, loop statement: for loop, while loop & do-while loop and jump statement: break and continue. 16) Which of the following statements are correct about below C-program?
The options are given below:
The correct option is (b). Explanation: The statement 1 is true because x=100 and y=20 is the output of a program. The statement 2 is false because printf() function is not inside for loop. Therefore printf statement only runs for 1 time. The statement 3 is true because the semicolon is used for terminating a conditional statement. Therefore if(x!=y); is allowed in C. The statement 4 is false because the program is producing output x=100 and y=20. Therefore only statement 1 and 3 are correct statement. 17) Which of the following statements are correct about for loop in C-program?
The options are given below:
The correct option is (d). Explanation: For loop is used if we want statements in loop get executed at least once. Therefore for loop works slower than a while loop i.e. statement 3 is incorrect. Remaining 3 statements about for loop is correct. Therefore statement 1, 2, 4 are the correct statements. 18) What is the output of the given program, if a short int is 2 bytes wide?
The correct option is (b). Explanation: In for loop expression i.e. for(i<=5 && i>=-1; ++i; i>0) the expression i<=5 && i>=-1 is the loop condition. Expression ++i increment the expression. In given for loop condition the loop start from 1and it gets executed till the limit of integer i.e. 65535. Therefore the output of the program is 1 ... 65535. 19) Can we use switch statement to switch on strings in C?
The correct option is (b). Explanation: In switch statemen,t the cases must be either constant expression or an integer constant. Therefore it is not allowed to use switch statement to switch on strings in C programming. 20) What is the output of the given program?
The correct option is (b). Explanation: A do-while allows body of the loop to get executed before testing the condition. Therefore to begin with, value of a, i.e. 5, gets printed, and then the control reaches the statement a=-1. Since -1 is not greater than 0, so the condition fails and the loop is terminated at the value of a=5. Therefore the output of program is 5. |