Control Structures MCQs

155 questionsC-ProgramPage 7 of 18

Practice free Control Structures multiple-choice questions with instant answer feedback and step-by-step solutions. Click an option to check yourself, reveal the full explanation, and work through all 155 questions — no login required.

Question 55hard
What will be the following code's output if choice = 'R'?
switch(choice)
{
   case 'R' : printf("RED");
   case 'W' : printf("WHITE");
   case 'B' : printf("BLUE");
   default  : printf("ERROR");break;
}
Question 56hard
Consider the following program fragment:
for(c=1, sum=0; c <= 10; c++)
{
   scanf("%d", &x);
   if( x < 0 ) continue;
   sum += x;
}
What would be the value of sum for the input 1, -1, 2, -2, 3, -3, 4, -4, 5, -5
Question 57hard
What will be printed if the following code is executed?
void main()
{
   int x=0;
   for( ; ; )
   {
      if( x++ == 4 ) break;
      continue;
   }
   printf("x=%d", x);
}
Advertisement
Question 58easy
Consider the following code:
void main()
{
   int a[5] = {6,8,3,9,0}, i=0;
   if(i != 0)
   {
      break;
      printf("%d", a[i]);
   }
   else
      printf("%d", a[i++]);
}

What is the output of the above program?
Question 59hard
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()
{
    int ch;
    printf("enter a value between 1 to 2:");
    scanf("%d", &ch);
    switch (ch, ch + 1)
    {
       case 1:
          printf("1\n");
          break;
       case 2:
          printf("2");
          break;
    }
}
Question 60medium
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int i = 0;
    do
    {
        printf("Hello");
    } while (i != 0);
}
Advertisement
Question 61hard
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 0;
    while (i < 2)
    {
        if (i == 1)
            break;
            i++;
            if (i == 1)
                continue;
                printf("In while loop\n");
    }
    printf("After loop\n");
}
Question 62hard
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int i = 0, k;
    label: printf("%d", i);
    if (i == 0)
        goto label;
}
Question 63hard
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int x = 97;
    switch (x)
    {
       case 'a':
          printf("yes ");
          break;
       case 97:
          printf("no\n");
          break;
    }
}