C Control Statements Test 2C control statements test paper 2 contains questions from decision statement: if-else and switch, loop statement: for loop, while loop & do-while loop and jump statement: break and continue. 6) Find out the error, if any in the while loop of below program.
The correct option is (c). Explanation: In program "Expression syntax" error occur because the while() loop must have conditional expression. For Example: while (j >5) { ... } Therefore for removing the ?Expression syntax? error there should be a condition in the while loop. 7) If scanf() statement is used for storing a value in char variable, then along with the value a carriage return (\r) also gets stored.
The correct option is (b). Explanation: No, if scanf() statement is used then the carriage return tells the compiler to read the input from buffer after the ENTER key is pressed by the user. Therefore the value of carriage return (\r) is not get stored in memory. 8) Find out whether both the loops in a program prints the correct string length?
The correct option is (c). Explanation: In while loop the incorrect string length is printed because while loop variable 'i' get incremented after checking for '\0', hence giving 1 more than the length of string. Therefore only for loop prints the correct string length. 9) The break statement is used to take control out of switch and continue statement is used to take control of the beginning of the switch?
The correct option is (b). Explanation: No, because continue statement can work only with loops in C-programming and not with switch. 10) For printing the value of a and b given below, which printf() statement will you use?
The correct option is (d). Explanation: For printing the double value %lf is used as format specifier. For printing the float value %f is used as format specifier. Therefore for printing the value of a and b the syntax of printf statement is printf("%f %lf", a, b); |