250+ TOP MCQs on If-then-else Statements and Answers

C helps anyone preparing for Infosys and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Infosys interviews on C Programming language.

Here is a listing of C test questions on “If-then-else Statements” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         if (x > 0)
  6.             printf("inside ifn");
  7.         else if (x > 0)
  8.             printf("inside elseifn");
  9.     }

a) inside if
b) inside elseif
c)

inside if
inside elseif

d) compile time error
Answer: a
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 0;
  5.         if (x++)
  6.             printf("truen");
  7.         else if (x == 1)
  8.             printf("falsen");
  9.     }

a) true
b) false
c) compile time error
d) undefined behaviour
Answer: b
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 0;
  5.         if (x == 1)
  6.             if (x == 0)
  7.                 printf("inside ifn");
  8.             else
  9.                 printf("inside else ifn");
  10.         else
  11.             printf("inside elsen");
  12.     }

a) inside if
b) inside else if
c) inside else
d) compile time error
Answer: c
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  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("%dn", x);
  10.     }

a) false, 0
b) true, 0
c) true, 10
d) compile time error
Answer: b
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 0;
  5.         if (x == 1)
  6.             if (x >= 0)
  7.                 printf("truen");
  8.             else
  9.                 printf("falsen");
  10.     }

a) true
b) false
c) Depends on the compiler
d) No print statement
Answer: d
Clarification: None.

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
Clarification: None.

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
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  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
Clarification: None.

9. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1;
  5.         if (a)
  6.             printf("All is Well ");
  7.             printf("I am Welln");
  8.         else
  9.             printf("I am not a Rivern");
  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
Clarification: None.

10. What will be the output of the following C code?

  1.     #include 
  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
Clarification: None.

  250+ TOP MCQs on Break and Continue and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top