C Control Statements Test Quiz On C Control Statements

  • enum
  • character
  • integer
  • float

Explanation:

In the C programming language, the switch/case statement is mandated by the language specification to operate with an integer value. As a result, it is not permissible to utilize a floating-point value within a switch/case statement.

2) How many times "javaLogic Practice" is printed?

Example

#include<stdio.h>

int main()

{

    int x;

    for(x=-1; x<=10; x++)

    {

        if(x < 5)

            continue;

        else

            break;

        printf("javaLogic Practice");

    }

    return 0;

}
  • 10 times
  • 11 times
  • 0 times
  • Infinite times

Explanation:

In the program, the variable x is set to -1 initially. Since x is less than 5 (as x is -1), the code will begin with the continue statement.

Continue refers to "skipping the current iteration and moving on to the next iteration" in programming. As a result, the value of x is reset to 0 at this point. This process will repeat until x reaches a value of 5.

If the value assigned to x is 5, the program will execute the code inside the else block, triggering the break statement. Consequently, it will exit the for loop without reaching the printf statement.

As a result, the javaLogic Practice will not be displayed at all.

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

Example

#include<stdio.h>

int main()

{

    int i=1;

    while(i <= 155)

    {

        printf("%c %d\n", i, i);

        i++;

    }

    return 0;

}
  • 154 times
  • 155 times
  • 156 times
  • Infinite times

Explanation:

The dimension of a short integer, which is 2 bytes in width, does not impact the operation of the while loop.

As a result, the loop will iterate 155 times while the condition (i <= 155) is met.

4) Which statement is correct about the below program?

Example

#include<stdio.h>

int main()

{

    int i = 8, j = 24;

    if(i = 8) && if(j = 24)

        printf("Welcome Programmer");

    return 0;

}
  • Welcome Programmer
  • Error: Undeclared identifier if
  • Error: Expression syntax
  • No output

Explanation:

In the 5th line of the program, when the condition if(i == 8) && if(j == 24) is used, an "Expression syntax" error is triggered.

Therefore, the expression should appear as if((i == 5) && (j == 10)).

As a result of compiling the program, an error is being encountered related to expression syntax.

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

Example

#include<stdio.h>

int main()

{

    int j = 1;

    switch(j)

    {

        printf("Hello programmer!");

        case 1:

            printf("Case1");

            break;

        case 2:

            printf("Case2");

            break;

    }

return 0;

}
  • No error in program and prints "Case1"
  • Error: Invalid printf statement after switch statement
  • Error: No default specified
  • None of the above

Explanation:

In programming, the switch statement is utilized to evaluate different cases based on the value of the expression inside the parentheses. In this scenario, the switch statement is modified to switch(1) because the variable 'j' is initialized with a value of 1.

As a result, when case 1 is met, the block is executed, leading to the output of "Case1".

The statement Printf ("Hello programmer!"); is disregarded by the compiler.

Therefore, the program is free of errors and will output "Case1".

Input Required

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