Log In Register

Units


If-then-else Statements - Questions and Answers

 

Practice these If-then-else Statements under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on If-then-else Statements for following purpose.


– Anyone who is wishing to increase their perfect knowledge of If-then-else Statements of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically If-then-else Statements.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on If-then-else Statements under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  If-then-else Statements topic of C Programming:

 

1.

What is the output of this 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.     }

Answer: Option A

Explanation:

2.

What is the output of this 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.     }

Answer: Option D

Explanation:

3.

Comment on the output of this 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.     }

Answer: Option A

Explanation:

4.

What is the output of this 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.     }

Answer: Option D

Explanation:

5.

When 1 is entered, The output of the code below is?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 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.     }

Answer: Option D

Explanation:

6.

if (a == 1||b == 2){} can be written as:

Answer: Option A

Explanation:

7.

What is the output of this 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.     }

Answer: Option C

Explanation:

8.

When 1 is entered, The output of the code below is?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int ch;
  5.         printf("enter a value btw 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.     }

Answer: Option C

Explanation:

9.

The output of the code below is(when 1 is entered)

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double ch;
  5.         printf("enter a value btw 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.     }

Answer: Option D

Explanation:

10.

The output of the code below is

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 5;
  5.         if (x < 1);
  6.             printf("Hello");
  7. 
     
  8.     }

Answer: Option B

Explanation:

11.

The output of the code below is

  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.     }

Answer: Option C

Explanation:

12.

The output of the code below is

  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.     }

Answer: Option A

Explanation:

13.

The output of the code below is

  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.     }

Answer: Option C

Explanation:

14.

What is the output of this 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.     }

Answer: Option D

Explanation:

15.

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

Answer: Option D

Explanation: