• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Loops & Control Structure

Question 11

Output of following C program? C
#include<stdio.h>
int main()
{
    int i = 0;
    for (printf(\"1st\\n\"); i < 2 && printf(\"2nd\\n\"); ++i && printf(\"3rd\\n\"))
    {
        printf(\"*\\n\");
    }
    return 0;
}
  • 1st
    2nd
    *
    3rd
    2nd
    *
  • 1st
    2nd
    *
    3rd
    2nd
    *
    3rd
  • 1st
    2nd
    3rd
    *
    2nd
    3rd
  • 1st
    2nd
    3rd
    *
    1st
    2nd
    3rd

Question 12

C
#include <stdio.h>   
int main() 
{ 
  int i;   
  for (i = 1; i != 10; i += 2) 
    printf(\" GeeksQuiz \"); 
  return 0; 
}
  • GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz
  • GeeksQuiz GeeksQuiz GeeksQuiz .... infinite times
  • GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz
  • GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz GeeksQuiz

Question 13

What will be the output of the following C program segment? (GATE CS 2012) C
char inchar = \'A\';
switch (inchar)
{
case \'A\' :
    printf (\"choice A \\n\") ;
case \'B\' :
    printf (\"choice B \") ;
case \'C\' :
case \'D\' :
case \'E\' :
default:
    printf (\"No Choice\") ;
}
  • No choice
  • Choice A
  • Choice A
    Choice B No choice
  • Program gives no output as it is erroneous

Question 14

Predict the output of the below program: C
#include <stdio.h>
int main()
{
    int i = 3;
    switch(i)
    {
        printf(\"Outside \");
        case 1: printf(\"Geeks\");
            break;
        case 2: printf(\"Quiz\");
            break;
        defau1t: printf(\"GeeksQuiz\");
    }
    return 0;
}
  • Outside GeeksQuiz
  • GeeksQuiz
  • Nothing gets printed

Question 15

In the following program, X represents the Data Type of the variable check. C
#include <stdio.h>
int main()
{
    X check;
    switch (check)
    {
        // Some case labels
    }
    return 0;
} 
Which of the following cannot represent X?
  • int
  • char
  • enum
  • float

Question 16

What is the output of the following program? C
#include <stdio.h>
int main()
{
    char check = \'a\';
    switch (check)
    {
        case \'a\' || 1: printf(\"Geeks \");
        
        case \'b\' || 2: printf(\"Quiz \");
                    break;
        default: printf(\"GeeksQuiz\");
    }
    return 0;
}
  • Geeks
  • Geeks Quiz
  • Geeks Quiz GeeksQuiz
  • Compile-time error

Question 17

Predict the output of the following program: C
#include <stdio.h>
int main()
{
    int check = 20, arr[] = {10, 20, 30};
    switch (check)
    {
        case arr[0]: printf(\"Geeks \");
        case arr[1]: printf(\"Quiz \");
        case arr[2]: printf(\"GeeksQuiz\");
    }
    return 0;
}
  • Quiz
  • Quiz GeeksQuiz
  • GeeksQuiz
  • Compile-time error

Question 18

How many times GeeksQuiz is printed C
#include<stdio.h>
int main()
{
    int i = -5;
    while (i <= 5)
    {
        if (i >= 0)
            break;
        else
        {
            i++;
            continue;
        }
        printf(\"GeeksQuiz\");
    }
    return 0;
}
  • 10 times
  • 5 times
  • Infinite times
  • 0 times

Question 19

C
#include <stdio.h>
int main()
{
    int i = 3;
    while (i--)
    {
        int i = 100;
        i--;
        printf(\"%d \", i);
    }
    return 0;
}
  • Infinite Loop
  • 99 99 99
  • 99 98 97
  • 2 2 2

Question 20

C
#include <stdio.h>
int main()
{
    int x = 3;
    if (x == 2); x = 0;
    if (x == 3) x++;
    else x += 2;

    printf(\"x = %d\", x);

    return 0;
}
  • x = 4
  • x = 2
  • Compiler Error
  • x = 0

There are 45 questions to complete.

Last Updated :
Take a part in the ongoing discussion