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 2 Question 42 Discussion

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

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

#include

using namespace std;

int main(){

int *i;

i = new int;

*i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4;

cout << *i;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Shantell
9 hours ago
This looks like a tricky one. I'll need to carefully work through the expression step-by-step to figure out the result.
upvoted 0 times
...
Kerrie
1 months ago
Haha, the code looks like it's performing some sort of cosmic dance with the numbers. I wonder what the output will be?
upvoted 0 times
...
Buddy
2 months ago
Ooh, this looks like a trick question. I'm going to go with D just to be safe.
upvoted 0 times
...
Marylyn
2 months ago
Hmm, let me think about this... Doesn't integer division always truncate the result? I'm going with B!
upvoted 0 times
...
Pearly
2 months ago
Wait, are we supposed to use floating-point arithmetic or integer arithmetic? I'm so confused!
upvoted 0 times
...
Lorriane
2 months ago
That makes sense, I can see how the calculations would lead to that result
upvoted 0 times
...
Willodean
2 months ago
I think the correct answer is C) It prints: 2 because of the arithmetic operations in the code
upvoted 0 times
...
Dortha
2 months ago
But doesn't the code involve some calculations that might result in a different output?
upvoted 0 times
...
Lorriane
2 months ago
I believe the answer is B) It prints: 1
upvoted 0 times
...
Dortha
3 months ago
I think the answer is A) It prints: 0
upvoted 0 times
...

Save Cancel