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


Please Help Members By Posting Answers For Below Questions

Explain about block scope in c?

667


Explain the difference between structs and unions in c?

585


What are the advantages of using macro in c language?

596


Why c is called object oriented language?

592


When should the const modifier be used?

662






can anyone suggest some site name..where i can get some good data structure puzzles???

1649


Why is C language being considered a middle level language?

660


which is an algorithm for sorting in a growing Lexicographic order

1403


How the c program is executed?

639


What does sizeof function do?

623


Explain what are its uses in c programming?

600


Do you know the use of 'auto' keyword?

666


write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1639


WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2032


What does the format %10.2 mean when included in a printf statement?

1095