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

6/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>
void main()
{
    int i = 0;
    if (i == 0)
    {
        goto label;
    }
    label: printf("Hello");
}

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 = 0;
    if (i == 0)
    {
        printf("Hello");
        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 = 0;
    if (x == 0)
        printf("hi");
    else
        printf("how are u");
        printf("hello");
}

Select an option to see the answer and solution.

Which keyword can be used for coming out of recursion?

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 = 0, k;
    if (i == 0)
        goto label;
        for (k = 0;k < 3; k++)
        {
            printf("hi ");
            label: k = printf("%03d", 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()
{
    int i = 0, j = 0;
    while (i < 5, j < 10)
    {
        i++;
        j++;
    }
    printf("%d, %d\n", i, j);
}

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 (true);
        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 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>
void main()
{
    int i = 0;
    if (i == 0)
    {
        printf("Hello");
        continue;
    }
}

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 x;
void main()
{
    if (x)
        printf("hi");
    else
        printf("how are u");
}

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 (foo(); i == 1; i = 2)
        printf("In for loop\n");
        printf("After loop\n");
}
int foo()
{
    return 1;
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    float f = 1;
    switch (f)
    {
       case 1.0:
          printf("yes\n");
          break;
       default:
          printf("default\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;
    char c = 'a';
    while (i < 2)
    {
        i++;
        switch (c) 
        {
           case 'a':
               printf("%c ", c);
               break;
               break;
        }
    }
    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 a = 1;
    if (a--)
        printf("True");
        if (a++)
            printf("False");
}

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);
}
void foo()
{
    l1: printf("3 ", 3);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char *str = "";
    do
    {
        printf("hello");
    } while (str);
}

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 = 0;
    for (i = 0;i < 5; i++)
        if (i < 4)
        {
            printf("Hello");
            break;
        }
}

Select an option to see the answer and solution.

Which of the following is an invalid if-else statement?

Select an option to see the answer and solution.

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

}

Select an option to see the answer and solution.