Answer to Question #23965 in C++ for Nourh

Question #23965
3. What is output by the following code?
int c = 4;
int d = 5;
if ((d > c) && (d % 2 == 0)) {
cout << “Elvis is alive.” << endl;
} else {
cout << “Elvis is with Mama Kass.” << endl;
}
1
Expert's answer
2013-02-08T04:58:03-0500
int c = 4;
int d = 5;
if ((d > c) && (d % 2 == 0))
& cout << "Elvis is alive." << endl;
else
& cout << "Elvis is with Mama Kass." << endl;
&
The output of this code is:

Elvis is with Mama Kass.

because the 'if' condition is false:
(d > c) = (5 > 4) ~ true
(d % 2) = (5 % 2) = 1, (1 == 0) ~ false

(true && false) = false,
so the 'else' code branch is executed.

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
APPROVED BY CLIENTS