Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 269 - 269 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 269

C & C Plus Plus

Question

MCQ▾

What is the output in the following program

  1. main ()
  2. {
  3.     charc =-64;
  4.     inti =-32;
  5.     unsignedintu =-16;
  6.     if (c>i)
  7.     {
  8.         printf("pass1,");
  9.         if(c)
  10.         printf ("pass2,");
  11.         else
  12.         printf ("Fail2");
  13.     }
  14.     else
  15.     printf ("Fail1,");
  16.     if (i)
  17.     printf ("pass2");
  18.     else
  19.     printf ("Fail2");
  20. }

Choices

Choice (4)

a.

Pass1, fail2

b.

Fail1, fail2

c.

Pass1, pass2

d.

Fail1, pass2

Answer

d.

Explanation

  • In the program
Table Showing the Program
char c =-64;
  • Define the character variable c =-64
int i =-32;
  • Define the integer variable i =-32
unsigned int u =-16;
  • Define the unsigned integer u =-16
  1. if (c >i)
  2. {
  3.     printf(“pass1,“);
  4.     if(c)
  5.     printf (“pass2,“);
  6.     else
  7.     printf (“Fail2”);
  8. }
  9. else
  10. printf (“Fail1,“);
  • Check the if condition
  1. if (-64 >-32)
  2. {
  3.     printf(“pass1,“);
  4.     if(c)
  5.     printf (“pass2,“);
  6.     else
  7.     printf (“Fail2”);
  8. }
  9. else
  10. printf (“Fail1,“);
  • Here if condition is false because -64 is less -32
  • So, else condition is applied
  • And printf prints “Fail1”
  1. if (i)
  2. printf (“pass2”);
  3. else
  4. printf (“Fail2”);
  • Check the if condition
  1. if (-32)
  2. printf (“pass2”);
  3. else
  4. printf (“Fail2”);
  • Here if condition is true
  • So, printf prints “pass2”

Developed by: