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 volatile variables in c?
What extern c means?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
Explain how can you restore a redirected standard stream?
What is structure data type in c?
Explain what is a 'locale'?
Why we write conio h in c?
Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
How can I check whether a file exists? I want to warn the user if a requested input file is missing.
How is null defined in c?
What are header files in c programming?
Is c is a high level language?
List out few of the applications that make use of Multilinked Structures?
What are global variables?