Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPA-21-02 Topic 8 Question 22 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 22
Topic #: 8
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int fun(int x) {

return x<<2;

}

int main(){

int i;

i = fun(1) / 2;

cout << i;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Chaya
5 hours ago
I think the answer is C) It prints: 2. The bit-shift operation `x<<2` effectively multiplies `x` by 4, so `fun(1)` returns 4, and when divided by 2, the result is 2.
upvoted 0 times
...
Veronica
3 days ago
The correct answer is B) It prints: 1. The function `fun(1)` returns 4, and when divided by 2, the result is 2.
upvoted 0 times
...
Levi
3 days ago
I'm not sure, but I think the answer might be C.
upvoted 0 times
...
Laurene
7 days ago
I agree with Daniel, because the function fun() shifts the bits of the input left by 2 positions.
upvoted 0 times
...
Daniel
10 days ago
I think the answer is D.
upvoted 0 times
...

Save Cancel