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
What are void pointers in c?
What are the advantages of union?
Why malloc is faster than calloc?
What are categories used for in c?
What is a method in c?
Difference between MAC vs. IP Addressing
What are qualifiers?
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
What is meant by high-order and low-order bytes?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What are pointers? Why are they used?
Explain what is the difference between functions abs() and fabs()?
What is the function of multilevel pointer in c?
What is type qualifiers?
How to Throw some light on the splay trees?