English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

int result=0;
int option=1;
switch (option) {
case 0: result=result+1;
case 1: result=result+2;
case 2: result=result+3;
}

2006-11-13 17:03:20 · 6 answers · asked by HelpNeeded 1 in Computers & Internet Programming & Design

6 answers

you wont get that far because you will get a compile error first (no break;).

2006-11-14 00:57:55 · answer #1 · answered by justme 7 · 0 0

The program will enter in the second case statement. But as there is no break after this case statement, the following statement will be executed.
So the value of result will be result + 2 =2 and then result + 3 = 5.

2006-11-13 17:08:20 · answer #2 · answered by manoj Ransing 3 · 0 0

Since the variable option = 1, it would be case 1.
result = 0 + 2

So the answer is 2.

2006-11-13 17:05:31 · answer #3 · answered by Anonymous · 0 0

the answer would be 6

case 0 gives result =1
case 1 result =3
case 2 result =6

2006-11-14 05:15:08 · answer #4 · answered by life goes on... 2 · 0 0

the answer is 2 because
case 1: result=result+2;
and option is 1
so 0+=2
making it 2
btw u have bad syntax you have to put break statements depending on what language this is

2006-11-13 17:16:01 · answer #5 · answered by william10142001 2 · 0 0

DROP THE CLASS! YOU CAN'T PROGRAM!

QUIT ASKING US TO DO YOUR FREAKNG HOMEWORK! This is so easy, I could have answered everyone of your questions in the first week of Foundations to Computer Science 1.

2006-11-13 17:06:08 · answer #6 · answered by noon 1 · 1 0

fedest.com, questions and answers