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:

Genevive
29 days ago
Haha, this is a classic bit-shift question! The answer is definitely B) It prints: 1. I remember learning about this in my coding class, where the instructor said, 'Bit-shifting is like magic, but it's also like a secret handshake for programmers.'
upvoted 0 times
Dorsey
16 days ago
Actually, it prints: 1 because the function fun(1) shifts the binary representation of 1 two positions to the left.
upvoted 0 times
...
Shonda
20 days ago
I think the answer is D) It prints: 4.
upvoted 0 times
...
...
Lelia
1 months ago
Hmm, this is a tricky one. I'm going to go with D) It prints: 4. The bit-shift operation must be doing something weird, so let's just go with the largest number in the options.
upvoted 0 times
...
Chaya
2 months 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
Yen
19 days ago
That makes sense, the bit-shift operation is multiplying by 4.
upvoted 0 times
...
Wilson
21 days ago
I agree, the answer is C) It prints: 2.
upvoted 0 times
...
...
Veronica
2 months 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
2 months ago
I'm not sure, but I think the answer might be C.
upvoted 0 times
...
Laurene
2 months ago
I agree with Daniel, because the function fun() shifts the bits of the input left by 2 positions.
upvoted 0 times
...
Daniel
2 months ago
I think the answer is D.
upvoted 0 times
...

Save Cancel