Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the following C program segment?

char inchar = 'A';
switch (inchar)
{
case 'A' :
    printf ("choice A \n") ;
case 'B' :
    printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
    printf ("No Choice") ;
}

 

  • A.No choice
  • B.Choice A
  • C.Choice A
    Choice B No choice
  • D.Program gives no output as it is erroneous

Answer: C

Correct answer: Choice A Choice B No Choice

There is no break after the first printf, so execution falls through every following label. Matching case 'A' prints “choice A”, then “choice B”, then - passing through the empty labels C, D and E - the default prints “No Choice”. A case label marks an entry point, not a block.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.