Asked in NUST NET Mock Test 2 — Computer ScienceModerate

Find the output of the following code

Correct answer: C. a not a

  • A. a
  • B. not a
  • C. a not a
  • D. Compile the error Here's what happens:The variable ch is initialized with the character 'a'.The switch statement checks the value of ch.Since ch is 'a', it matches the case 'a' and executes printf("a");.However, there is no break statement after the first case, so the control falls through to the default case.As a result, it also executes printf("not a");.So, the correct output is:(c) a not a

Explanation

Compile the error Here's what happens:The variable ch is initialized with the character 'a'.The switch statement checks the value of ch.Since ch is 'a', it matches the case 'a' and executes printf("a");.However, there is no break statement after the first case, so the control falls through to the default case.As a result, it also executes printf("not a");.So, the correct output is:(c) a not a

Last updated

About Logical Problems

Logical problems present several conditions about people, objects, events or choices and require their possible arrangements to be tested. They cover constraint-based reasoning, rankings, matching, grouping, scheduling and elimination, with attention to the difference between a complete solution and a possibility that merely satisfies one condition.

Practise Logical Problems

439 free Logical Problems MCQs from Analytical and Logical Reasoning, each with the correct answer and an explanation. Unlimited attempts, no account needed.

Exams that ask Analytical and Logical Reasoning questions like this

Analytical and Logical Reasoning is on 24 papers prepared for on TestUstad, and all of them draw the same bank, so this question is worth knowing for every one of them.

Related questions