consider the following program sigment
int n,sum=1;
switch(n) {
case 2:sum=sum+2;
case 3:sum*=2;
break;
default:sum=0;}
if n=2, what is the value of sum
a.0
b.6
c.3
d.none
Answer Posted / manishsoni
# define prod(a,b) a*b
main()
{
int n=2,sum=1; //here given n=2 so
switch(n) //switch(2)
{
case 2: //encounter this case 2;
sum=sum+2; //add sum=1+2;sum=3
case 3: //here no break statement so case
// 3 is checked by this and
// remained that sum=3;
sum*=2; //so sum =3*2;sum=6
break; //here switch is break and sum=6;
default: //default is don't check ;
sum=0;
}
printf("%d",sum); //so print sum=6;
getch();
}
by manish soni MCA first sem (by rawatsar);
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
Is c easier than java?
Can i use “int” data type to store the value 32768? Why?
How can I invoke another program or command and trap its output?
What are the rules for the identifier?
How do you convert strings to numbers in C?
What is the purpose of realloc()?
What does a function declared as pascal do differently?
Why do we need volatile in c?
Explain null pointer.
What are shell structures used for?
Is it possible to execute code even after the program exits the main() function?
where are auto variables stored? What are the characteristics of an auto variable?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
What's a good way to check for "close enough" floating-point equality?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none