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

  1. b*2
  2. b*c-2
  3. b+c*2
  4. none of these
asked in Programming by (107 points)   | 42 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 Boss (8k points)  
+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 (10.9k points)  


Top Users Jun 2017
  1. Bikram

    3694 Points

  2. Hemant Parihar

    1484 Points

  3. junaid ahmad

    1432 Points

  4. Arnab Bhadra

    1398 Points

  5. Niraj Singh 2

    1311 Points

  6. Rupendra Choudhary

    1194 Points

  7. rahul sharma 5

    1114 Points

  8. Arjun

    930 Points

  9. srestha

    928 Points

  10. Debashish Deka

    896 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 19 - 25
  1. Bikram

    1950 Points

  2. Niraj Singh 2

    1306 Points

  3. junaid ahmad

    502 Points

  4. sudsho

    410 Points

  5. akankshadewangan24

    388 Points


23,354 questions
30,065 answers
67,363 comments
28,382 users