GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
54 views

  1. b*2
  2. b*c-2
  3. b+c*2
  4. none of these
asked in Programming by (219 points) 1 2 10 | 54 views

2 Answers

+3 votes

Lets take all the options one by one.

Given, a=32, b=2, c=3.

(A) b*2 is 4. switch(4) will execute case 4, which will give output as 2, after that control will come out of switch block due to break.

(B) b*c-2 is 4. Output will be same as above.

(C) b+c*2 is 8. switch(8) will execute case 8. So, 3 will be printed. But since there is no break statement, default will also be executed. So, 2 will be printed. Hence, 32 will be the output.

So, option (C).

answered by Veteran (10.2k points) 6 43 108
+2 votes

After every case there is a need of break statement otherwise consecutive cases also executed.

switch(x)

{

case 2;  ...

case 3:...

break;

}

suppose if x=2 then case 2 , case3 and default also executed.

In the given question if X=b+c*2=2+3*2=8.

switch(8)  ..it execute case 8 and default.

case 8 prints c=3 and default prints b=2 and the o/p is 32.

Hence answer should be 3.

answered by Veteran (11.6k points) 6 20 88

Related questions

0 votes
1 answer
1
asked in Programming by vijay_jr (219 points) 1 2 10 | 65 views
+1 vote
0 answers
2
asked in Programming by Jason_Roy Junior (785 points) 1 4 13 | 62 views
+3 votes
1 answer
3
asked in Programming by indrajeet Active (1.9k points) 3 43 80 | 63 views


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23678 Points

  2. Bikram

    17268 Points

  3. Habibkhan

    8950 Points

  4. srestha

    6446 Points

  5. Debashish Deka

    5478 Points

  6. jothee

    5128 Points

  7. Sachin Mittal 1

    4882 Points

  8. joshi_nitish

    4486 Points

  9. sushmita

    4032 Points

  10. Rishi yadav

    3974 Points


Recent Badges

Popular Question Hira Thakur
Notable Question amaity
Notable Question srestha
Nice Answer Madhab
Renewal Madhab
Popular Question sourabh
Notable Question K ANKITH KUMAR
Great Answer saloni
Resurrection saloni
Great Question Ishrat Jahan
27,406 questions
35,255 answers
84,502 comments
33,454 users