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

  1. b*2
  2. b*c-2
  3. b+c*2
  4. none of these
asked ago in Programming by (59 points)   | 22 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 ago by Boss (5.3k 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 ago by Boss (9.4k points)  

Related questions

0 votes
1 answer
1
asked ago in Programming by vijay_jr (59 points)   | 34 views
+1 vote
1 answer
2
asked in Programming by thor Boss (8.3k points)   | 81 views
0 votes
1 answer
3
asked in Programming by gautamcse27 (293 points)   | 103 views
Top Users Jan 2017
  1. Debashish Deka

    7050 Points

  2. Habibkhan

    4674 Points

  3. Vijay Thakur

    4224 Points

  4. saurabh rai

    4008 Points

  5. sudsho

    3960 Points

  6. Arjun

    3108 Points

  7. GateSet

    3088 Points

  8. santhoshdevulapally

    3004 Points

  9. Bikram

    2976 Points

  10. Sushant Gokhale

    2744 Points

Monthly Topper: Rs. 500 gift card

18,810 questions
23,779 answers
51,414 comments
20,128 users