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

5/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;
    l1: while (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? (Assuming that we have entered the value 1 in the standard input)
#include <stdio.h>
void main()
{
    double ch;
    printf("enter a value between 1 to 2:");
    scanf("%lf", &ch);
    switch (ch)
    {
       case 1:
          printf("1");
          break;
       case 2:
          printf("2");
          break;
    }
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    printf("%d ", 1);
    goto l1;
    printf("%d ", 2);
    l1:goto l2;
    printf("%d ", 3);
    l2:printf("%d ", 4);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    if (printf("%d", printf(")))
        printf("We are Happy");
    else if (printf("1"))
        printf("We are Sad");
}

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 < 3; 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>
const int a = 1,  b = 2;
int main()
{
    int x = 1;
    switch (x)
    {
       case a:
          printf("yes ");
       case b:
          printf("no\n");
          break;
    }
}

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 x = 5;
    if (x < 1);
        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()
{
    int a = 0, i = 0, b;
    for (i = 0;i < 5; i++)
    {
        a++;
        continue;
    }
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    printf("%d ", 1);
    l1:l2:
    printf("%d ", 2);
    printf("%d\n", 3);
}

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;
    while (i = 0)
        printf("True\n");
    printf("False\n");
}

Select an option to see the answer and solution.

The C statement ""if (a == 1 || b == 2) {}"" can be re-written as . . . . . . . .

Select an option to see the answer and solution.

goto can be used to jump from main() to within a function.

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 x = 0;
    if (x++)
        printf("true\n");
    else if (x == 1)
        printf("false\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 a = 1;
    if (a)
        printf("All is Well ");
        printf("I am Well\n");
    else
        printf("I am not a River\n");
}

Select an option to see the answer and solution.

Which keyword is used to come out of a loop only for that iteration?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    printf("before continue ");
    continue;
    printf("after continue\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 a = 0, i = 0, b;
    for (i = 0;i < 5; i++)
    {
        a++;
        if (i == 3)
            break;
    }
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
switch (ch)
{
   case 'a':
   case 'A':
      printf("true");
}

Select an option to see the answer and solution.

How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in both the cases?
while (i < n)
         i++;
    ————-
    do
         i++;
    while (i <= n);

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.