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

What is the use of clrscr?

587


How to explain the final year project as a fresher please answer with sample project

463


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

774


When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

797


Is using exit() the same as using return?

666






What is graph in c?

577


What do you understand by friend-functions? How are they used?

639


Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58

1114


What is the maximum length of an identifier?

657


How to create struct variables?

584


What does 4d mean in c?

932


Describe newline escape sequence with a sample program?

645


Stimulate calculator using Switch-case-default statement for two numbers

2440


What is s in c?

605


What is the newline escape sequence?

577