Home » C Control Statements Test 1

C Control Statements Test 1

by Online Tutorials Library

C Control Statements Test 1

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

  1. enum
  2. character
  3. integer
  4. float

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 “tutoraspire” is printed?

  1. 10 times
  2. 11 times
  3. 0 times
  4. Infinite times

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 tutoraspire will be printed 0 times.

3) How many times while loop is executed if a short int is 2 byte wide?

  1. 154 times
  2. 155 times
  3. 156 times
  4. Infinite times

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?

  1. Welcome Programmer
  2. Error: Undeclared identifier if
  3. Error: Expression syntax
  4. No output

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?

  1. No error in program and prints “Case1”
  2. Error: Invalid printf statement after switch statement
  3. Error: No default specified
  4. None of the above

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

You may also like