Vidyalelo
C Programming · all questions

Control Structures
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

155

Questions

7/8

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 0, j = 0;
    while (i < 2)
    {
        l1: i++;
        while (j < 3)
        {
            printf("loop\n");
            goto l1;
        }
    }
}

Select an option to see the answer and solution.

What will be the correct syntax for running two variable for loop simultaneously?

Select an option to see the answer and solution.

Which for loop has range of similar indexes of 'i' used in for (i = 0;i < n; i++)?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    do
        printf("In while loop ");
    while (0);
        printf("After loop\n");
}

Select an option to see the answer and solution.

What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input)
#include <stdio.h>
void main()
{
    int ch;
    printf("enter a value between 1 to 2:");
    scanf("%d", &ch);
    switch (ch)
    {
       case 1:
          printf("1\n");
          break;
          printf("hi");
       default:
          printf("2\n");
    }
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    switch (printf("Do"))
    {
       case 1:
          printf("First\n");
          break;
       case 2:
          printf("Second\n");
          break;
       default:
          printf("Default\n");
          break;
    }
}

Select an option to see the answer and solution.

Which datatype can accept the switch statement?

Select an option to see the answer and solution.

Which loop is most suitable to first perform the operation and then test the condition?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int k = 0;
    for (k)
        printf("Hello");
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    while ()
        printf("In while loop ");
    printf("After loop\n");
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 0, j = 0;
    while (l1: i < 2)
    {
        i++;
        while (j < 3)
        {
            printf("loop\n");
            goto l1;
        }
    }
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 0, j = 0;
    while (i < 2)
    {
        l1 : i++;
        while (j < 3)
        {
            printf("Loop\n");
            goto l1;
        }
    }
}

Select an option to see the answer and solution.

What is an example of iteration in C?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int i = 5, k;
    if (i == 0)
        goto label;
        label: printf("%d", i);
        printf("Hey");
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    for (int i = 0;i < 1; i++)
        printf("In for loop\n");
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 0;
    for (; ; ;)
        printf("In for loop\n");
        printf("After loop\n");
}

Select an option to see the answer and solution.

Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 0, j = 0;
    for (i; i < 2; i++){
        for (j = 0; j < 3; j++)
        {
            printf("1\n");
            break;
        }
        printf("2\n");
    }
    printf("after loop\n");
}

Select an option to see the answer and solution.

Comment on the output of the following C code.
#include <stdio.h>
int main()
{
    int a = 1;
    switch (a)
    case 1:
        printf("%d", a);
    case 2:
        printf("%d", a);
    case 3:
        printf("%d", a);
    default:
        printf("%d", a);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int a = 1, b = 1;
    switch (a)
    {
       case a*b:
          printf("yes ");
       case a-b:
          printf("no\n");
          break;
    }
}

Select an option to see the answer and solution.