C output type question

Q.  C programming:

main()
{
int x;
if ( x > 4) printf( “Brinda”);
else if ( x > 10) printf( “Karthik”);
else if ( x > 21 ) printf(“ Pradeep”);
else printf( “Sandeep”);
}

What will be the value of x so that “Karthik” will be printed?

- Published on 24 Jun 15

a. From 10 to 21
b. From 11 to 21
c. Grater then 10
d. None

ANSWER: None
 
The logic for this program would be if x> 4 Brinda will be printed if x>10 Brinda and Karthik will be printed and x> 21 Brinda,Karthik and Pradeep will be printed. Hence, None would be the answer for the above program.
 

    Discussion

  • chintan singhai   -Posted on 17 Aug 15
    your explanation is absolutely wrong it won't print anyname except brinda because the condition for every value after 4 will be true for printing brinda and won't jump to else condition because even for x>10 && x>21 ,x>4 will be true and it will continue to print brinda

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)