Control Structures (Part - 1)
1. What will be the output of the following C code?
     1.    #include <stdio.h>
     2.    void main()
     3.    {
     4.       int x = 5;
     5.       if (x < 1)
     6.          printf("hello");
     7.       if (x == 5)
     8.          printf("hi");
     9.       else
     10.         printf("no");
     11.   }
a) hi
b) hello
c) no
d) error
Answer: a
2. What will be the output of the following C code?
     1.    #include <stdio.h>
     2.    int x;
     3.    void main()
     4.    {
     5.       if (x)
     6.          printf("hi");
     7.       else
     8.          printf("how are u");
     9.    }
a) hi
b) how are you
c) compile time error
d) error
Answer: b
3. What will be the output of the following C code?
      1.     #include <stdio.h>
      2.     void main()
      3.     {
      4.        int x = 5;
      5.        if (true);
      6.           printf("hello");
      7.     }
a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent
Answer: b
4. What will be the output of the following C code?
     1.    #include <stdio.h>
     2.    void main()
     3.    {
     4.       int x = 0;
     5.       if (x == 0)
     6.          printf("hi");
     7.       else
     8.          printf("how are u");
     9.          printf("hello");
     10.   }
a) hi
b) how are you
c) hello
d) hihello
Answer: d
5. What will be the output of the following C code?
    1.     #include <stdio.h>
    2.     void main()
    3.     {
    4.        int x = 5;
    5.        if (x < 1);
    6.           printf("Hello");
    7.  
    8.     }
a) Nothing
b) Run time error
c) Hello
d) Varies
Answer: c
6. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
    1.     #include <stdio.h>
    2.     void main()
    3.     {
    4.        double ch;
    5.        printf("enter a value between 1 to 2:");
    6.        scanf("%lf", &ch);
    7.        switch (ch)
    8.        {
    9.          case 1:
    10.          printf("1");
    11.          break;
    12.         case 2:
    13.          printf("2");
    14.          break;
    15.       }
    16.    }
a) Compile time error
b) 1
c) 2
d) Varies
Answer: a
7. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
     1.    #include <stdio.h>
     2.    void main()
     3.    {
     4.       char *ch;
     5.       printf("enter a value between 1 to 3:");
     6.       scanf("%s", ch);
     7.       switch (ch)
     8.       {
     9.         case "1":
     10.          printf("1");
     11.          break;
     12.        case "2":
     13.          printf("2");
     14.          break;
     15.      }
     16.   }
a) 1
b) 2
c) Compile time error
d) No Compile time error
Answer: c
8. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
     1.    #include <stdio.h>
     2.    void main()
     3.    {
     4.       int ch;
     5.       printf("enter a value between 1 to 2:");
     6.       scanf("%d", &ch);
     7.       switch (ch)
     8.       {
     9.         case 1:
     10.          printf("1\n");
     11.        default:
     12.          printf("2\n");
     13.      }
     14.   }
a) 1
b) 2
c) 1 2
d) Run time error
Answer: c
9. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard
input)
     1.    #include <stdio.h>
     2.    void main()
     3.    {
     4.       int ch;
     5.       printf("enter a value between 1 to 2:");
     6.       scanf("%d", &ch);
     7.       switch (ch)
     8.       {
     9.         case 1:
     10.          printf("1\n");
     11.          break;
     12.          printf("Hi");
     13.        default:
     14.          printf("2\n");
     15.      }
     16.   }
a) 1
b) Hi 2
c) Run time error
d) 2
Answer: d
10. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
     1.    #include <stdio.h>
     2.    void main()
     3.    {
     4.       int ch;
     5.       printf("enter a value between 1 to 2:");
     6.       scanf("%d", &ch);
     7.       switch (ch, ch + 1)
     8.       {
     9.         case 1:
     10.          printf("1\n");
     11.          break;
     12.        case 2:
     13.          printf("2");
     14.          break;
     15.      }
     16.   }
a) 1
b) 2
c) 3
d) Run time error
Answer: b
1. What will be the output of the following C code?
     1.      #include <stdio.h>
     2.      int main()
     3.      {
     4.         int x = 1;
     5.         if (x > 0)
     6.            printf("inside if\n");
     7.         else if (x > 0)
     8.            printf("inside elseif\n");
     9.      }
a) inside if
b) inside elseif
c)
inside if
inside elseif
d) compile time error
Answer: a
2. What will be the output of the following C code?
     1.    #include <stdio.h>
     2.    int main()
     3.    {
     4.       int x = 0;
     5.       if (x++)
     6.          printf("true\n");
     7.       else if (x == 1)
     8.          printf("false\n");
     9.    }
a) true
b) false
c) compile time error
d) undefined behaviour
Answer: b
3. What will be the output of the following C code?
     1.      #include <stdio.h>
     2.      int main()
     3.      {
     4.         int x = 0;
     5.         if (x == 1)
     6.            if (x == 0)
     7.               printf("inside if\n");
     8.            else
     9.               printf("inside else if\n");
     10.        else
     11.           printf("inside else\n");
     12.     }
a) inside if
b) inside else if
c) inside else
d) compile time error
Answer: c
4. What will be the output of the following C code?
     1.     #include <stdio.h>
     2.     int main()
     3.     {
     4.        int x = 0;
     5.        if (x == 0)
     6.           printf("true, ");
     7.        else if (x = 10)
     8.           printf("false, ");
     9.        printf("%d\n", x);
     10.    }
a) false, 0
b) true, 0
c) true, 10
d) compile time error
Answer: b
5. What will be the output of the following C code?
     1.     #include <stdio.h>
     2.     int main()
     3.     {
     4.        int x = 0;
     5.        if (x == 1)
     6.           if (x >= 0)
     7.              printf("true\n");
     8.           else
     9.              printf("false\n");
     10.    }
a) true
b) false
c) Depends on the compiler
d) No print statement
Answer: d
6. The C statement “”if (a == 1 || b == 2) {}”” can be re-written as ___________
a)
   if (a == 1)
   if (b == 2){}
b)
   if (a == 1){}
   if (b == 2){}
c)
   if (a == 1){}
   else if (b == 2){}
d) none of the mentioned
Answer: d
7. Which of the following is an invalid if-else statement?
a) if (if (a == 1)){}
b) if (func1 (a)){}
c) if (a){}
d) if ((char) a){}
Answer: a
8. What will be the output of the following C code?
    1.     #include <stdio.h>
    2.     int main()
    3.     {
    4.        int a = 1;
    5.        if (a--)
    6.           printf("True");
    7.           if (a++)
    8.              printf("False");
    9.     }
a) True
b) False
c) True False
d) No Output
Answer: a
9. What will be the output of the following C code?
    1.     #include <stdio.h>
    2.     int main()
    3.     {
    4.        int a = 1;
    5.        if (a)
    6.           printf("All is Well ");
    7.           printf("I am Well\n");
    8.        else
    9.           printf("I am not a River\n");
    10.    }
a) Output will be All is Well I am Well
b) Output will be I am Well I am not a River
c) Output will be I am Well
d) Compile time errors during compilation
Answer: d
10. What will be the output of the following C code?
    1.    #include <stdio.h>
    2.    int main()
     3.    {
     4.       if (printf("%d", printf(")))
     5.          printf("We are Happy");
     6.       else if (printf("1"))
     7.          printf("We are Sad");
     8.    }
a) 0We are Happy
b) 1We are Happy
c) 1We are Sad
d) compile time error
Answer: d