Answer to Question #152424 in C++ for Usama Saleem

Question #152424
What will be the output of the following:

a) int n=10, d=0; if(x!=0 && n%d==0)cout<<"d divides n";

b) int n=10, d=0; if(n%d==0 && x!=0 )cout<<"d divides n";

c)
char key = 'y';
switch (key) {
case ‘y':
case ‘Y':
cout << "You choose \“y\"\n";
case ‘n':
case ‘N':
cout << "You choose quit\n";
break;
default:
cout << “invalid input\n”;
}


d)
int x=10;
if(x!=10)
if(x>10){
cout<<"big";
}
else{
cout<<"small";
}

e)
int x=10;
int main(){
if(1){
int x=30;
cout << x << endl;
x=x+1;
}
cout << x;
}
1
Expert's answer
2020-12-23T07:37:23-0500

a) if x variable is 0 , output will be nothing. Otherwise, it will be error (zero division (d = 0))

b)Output will be error (zero division (d = 0))

c) Output is

"You choose "y"

You choose quit"

Second line is shown because there is no "break" statement after 'y' case

d) Output is nothing because it's only if x is not 10

e) Output is

30(local)

10(global)


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog