Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - 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
1 months 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
Jeniffer
7 days ago
Oh, I see! So the result is 4, but then divided by 2 to get 2, which is printed out.
upvoted 0 times
...
Dorsey
1 months 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
1 months ago
I think the answer is D) It prints: 4.
upvoted 0 times
...
...
Lelia
2 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
Audra
8 days ago
User3: Yeah, let's go with D) It prints: 4
upvoted 0 times
...
Mariann
13 days ago
User2: I agree, the bit-shift operation is probably causing that
upvoted 0 times
...
Carmen
14 days ago
User1: I think it prints: 4
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
1 months ago
That makes sense, the bit-shift operation is multiplying by 4.
upvoted 0 times
...
Wilson
1 months 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
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77