Javatpoint Logo
Javatpoint Logo

C Control Statements Test 4

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

  1. The program produce the output x=100 y=20
  2. The printf() function run for 10 times
  3. The semi colon(;) after the if(x!=y) will not produce any error
  4. The program will produce no output

The options are given below:

  1. 2
  2. 1,3
  3. 3,4
  4. 4

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?

  1. All things that can be done using a for loop can also be done using a while loop.
  2. for loop can be used if we want statements in a loop get executed at least once.
  3. for loop works faster than a while loop.
  4. for(;;); implements an infinite loop.

The options are given below:

  1. 1
  2. 1, 2, 3
  3. 2, 3, 4
  4. 1, 2, 4

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?

  1. Expression syntax error
  2. 1 .... 65535
  3. 0, 1, 2, 3, 4, 5
  4. No output

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?

  1. Yes
  2. No

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?

  1. -1
  2. 5
  3. 0
  4. Compile error

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.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA