Javatpoint Logo
Javatpoint Logo

C Control Statements Test 3

C control statements test paper 3 contains questions from decision statement: if-else and switch, loop statement: for loop, while loop & do-while loop and jump statement: break and continue.


11) Which statements are correct about an if-else statement in a C-program?

  1. Nested if-else statements are allowed
  2. Every if-else statement can be replaced by an equivalent statement using ?: operators
  3. Multiple statement in else block are allowed
  4. Multiple statement in if block are allowed
  1. 1, 3 and 4
  2. 1, 2, 3 and 4
  3. 2 , 3and 4
  4. 1 and 4

The correct option is (a).

Explanation:

Nested if-else statement is allowed in C-program we can use if-else statement within if or else statement.

Multiple statements in if or else block are allowed because we can execute multiple statements against true value of if or else condition by placing the statements within { ?.. }.

Mostly if-else statement can be replaced by ternary operator but there are some exceptions also in which if-else statement cannot be replaced by ternary operator.

Therefore 1, 3 and 4 statements are correct about if-else statement.

12) Find out the error, if any in the below program?

  1. Error: Constant expression required at line case P:
  2. Error: There is no break statement in each case
  3. Error: No default value is specified
  4. No error

The correct option is (a).

Explanation:

On compiling the program compiler will report an error "constant expression required" in the line case P: because variable name is not allowed to be used with case statements.

The case statements only accept constant expression. Therefore the Error: Constant expression required at line case P: is occur.

13) Find out the error, if any in the below program?

  1. Error: in switch statement
  2. Error: in case 1*2+4 statement
  3. Error: No default specified
  4. No Error

The correct option is (d).

Explanation:

In switch statement constant expression are allowed therefore in case 1*2+4 statement it will give no error.

Therefore it prints "Case1" in the output of program.

14) A long integer is at least 32 bits wide and a short integer is at least 16 bits wide

  1. True
  2. False

The correct option is (a).

Explanation:

The basic C compiler used is 16 bit compiler, below are the size of their data types:

The size of long int is 4 bytes wide i.e. 32 bits.

The size of short int is 2 bytes wide i.e. 16 bits

15) A char variable can store either a Unicode character or an ASCII character.

  1. True
  2. False

The correct option is (a).

Explanation:

Yes, char variable is allowed to store either a Unicode character or an ASCII character because encoding of character data type is done in Unicode or ASCII format.





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA