C++ Institute CPA-21-02 Exam - Topic 8 Question 29 Discussion
What happens when you attempt to compile and run the following code?#include using namespace std;int fun(int x) {return 2*x;}int main(){int i;i = fun(1) || fun(2);cout
B) It prints: 1
A) It prints: 0
C) It prints: -1
D) Compilation error
C++ Institute CPA-21-02 Exam - Topic 8 Question 29 Discussion
Actual exam question for
C++ Institute's
CPA-21-02 exam
Okay, let me think this through. The || operator will return the first non-zero operand, or 0 if both operands are 0. So the key will be understanding the return values of the two function calls.
Ah, I think I've got this! The || operator will short-circuit, so the first function call that returns a non-zero value will determine the final result. I'll need to consider the return values of the two function calls.
Hmm, I'm a bit unsure about this one. The || operator can be confusing, and I'm not sure how it interacts with the function calls. I'll need to work through it step-by-step.
This looks like a tricky logical operation with the || operator. I'll need to carefully think through the order of evaluation and the return values of the two function calls.
Haha, the correct answer is obviously C. Because, you know, -1 is just a classic programmer's choice for a return value. Who needs 0 or 1 when you have -1, am I right?
Miles
8 months agoKimi
9 months agoAlida
9 months agoTijuana
9 months agoTyra
9 months agoParis
10 months agoSheron
10 months agoJovita
10 months agoTyisha
10 months agoDyan
10 months agoLenna
10 months agoMaxima
10 months agoRaul
10 months agoVilma
10 months agoLeontine
2 years agoNoe
2 years agoRodrigo
2 years agoCarmen
2 years agoMiesha
2 years agoHelaine
2 years agoLennie
2 years agoYvonne
2 years agoCarylon
2 years agoMariann
2 years agoCarisa
2 years agoAron
2 years agoCarisa
2 years agoCarisa
2 years agoErick
2 years agoBeckie
2 years agoViola
2 years ago