Javatpoint Logo
Javatpoint Logo

C Control Statements Test 2

C 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.

  1. There should be a semicolon in the while statement
  2. The while loop should be replaced with do-while loop
  3. There should be a condition in the while loop
  4. No error

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.

  1. True
  2. False

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?

  1. Yes, both the loops prints the correct string length
  2. Only while loop prints the correct string length
  3. Only for loop prints the correct string length
  4. Compile error in the program

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?

  1. Yes
  2. No

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?

  1. printf("%Lf %f", a, b);
  2. printf("%Lf %Lf", a, b);
  3. printf("%f %Lf", a, b);
  4. printf("%f %lf", a, b);

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);





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA