C Control Statements Test 1C control statements test paper contains questions from decision statement: if-else and switch, loop statement: for loop, while loop & do-while loop and jump statement: break and continue. 1) Which data type cannot be checked in switch-case statement?
The correct option is (d). Explanation: In C-languageswitch/case statement is defined by the language specification to use an int value therefore we cannot use a float value in switch/case statement. 2) How many times "javaTpoint" is printed?
The correct option is (c). Explanation: In program the x is initialized with -1. As x < 5 (since x is -1) it will start with continue statement. Continue means "stop the current iteration and proceed to the next iteration". Therefore x becomes 0 now. This will take place until x becomes 5. Now if the value of x=5, it will enter the else part where it encounters the break statement, as a result it will come out of for loop. Hence it will not go to printf statement. Therefore javaTpoint will be printed 0 times. 3) How many times while loop is executed if a short int is 2 byte wide?
The correct option is (b). Explanation: The size of short int which is 2 byte wide does not affect the while() loop operation. Therefore thewhile (i <= 155) loop will executed 155 times. 4) Which statement is correct about the below program?
The correct option is (c). Explanation: In program 5th line i.e. if(i = 8) && if(j = 24) the "Expression syntax" error occur. Hence the statement should be like if((i == 5) && (j == 10)). Therefore on compiling the program Error: Expression syntax is occurring. 5) Find out the error, if any in the below program?
The correct option is (a). Explanation: In program switch statement is used for switch(j) it becomes switch(1) because i is initialized with 1. Therefore the case 1: block is get executed. Hence it prints "Case1". Printf ("Hello programmer!"); is ignored by the compiler. Hence there is no error in program and prints "Case1". |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India