C Control Statement 3

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

Explanation:

Nested if-else statements are permissible in C programming, enabling the utilization of an if-else statement within another if or else statement.

It is permissible to have multiple statements within an if or else block as we can execute several statements when the condition evaluates to true by enclosing them within curly braces { }.

In many cases, ternary operators can be used as a concise alternative to if-else statements. However, there are certain scenarios where if-else statements are necessary and cannot be substituted by ternary operators.

Hence, statements 1, 3, and 4 accurately describe the if-else statement.

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

Example

#include<stdio.h>
int main()
{
    int P = 10;
    switch(P)
    {
       case 10:
       printf("Case 1");

       case 20:
       printf("Case 2");
       break;

       case P:
       printf("Case 2");
       break;
    }
    return 0;
}
  • Error: Constant expression required at line case P:
  • Error: There is no break statement in each case
  • Error: No default value is specified
  • No error

Explanation:

On compiling the program, the compiler will generate an error stating "constant expression required" at the line containing the case P statement. This issue arises because case statements do not support the usage of variable names.

The case statements only allow constant expressions. Hence, an Error: Constant expression required at line case P: is triggered.

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

Example

#include<stdio.h>
int main()
{
    int i = 1;
    switch(i)
    {
        case 1:
           printf("Case1");
           break;
        case 1*2+2:
           printf("Case2");
           break;
    }
return 0;
}
  • Error: in switch statement
  • Error: in case 1*2+4 statement
  • Error: No default specified
  • No Error

Explanation:

In a switch statement, constant expressions are permissible, which is why there will be no error in the case of the expression 1*2+4.

As a result, the program will display "Case1" in the output.

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

  • True
  • False

Explanation:

The primary C compiler in use is a 16-bit compiler, with the following sizes assigned to its data types:

The long int data type has a width of 4 bytes, equivalent to 32 bits.

The short int data type has a width of 2 bytes, which is equivalent to 16 bits.

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

  • True
  • False

Explanation:

Yes, a char variable can hold either a Unicode character or an ASCII character since the character data type is encoded in Unicode or ASCII format.

Input Required

This code uses input(). Please provide values below: