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:

Marylyn
3 days ago
Hmm, let me think about this... Doesn't integer division always truncate the result? I'm going with B!
upvoted 0 times
...
Pearly
5 days ago
Wait, are we supposed to use floating-point arithmetic or integer arithmetic? I'm so confused!
upvoted 0 times
...
Lorriane
6 days ago
That makes sense, I can see how the calculations would lead to that result
upvoted 0 times
...
Willodean
7 days ago
I think the correct answer is C) It prints: 2 because of the arithmetic operations in the code
upvoted 0 times
...
Dortha
11 days ago
But doesn't the code involve some calculations that might result in a different output?
upvoted 0 times
...
Lorriane
27 days ago
I believe the answer is B) It prints: 1
upvoted 0 times
...
Dortha
1 months ago
I think the answer is A) It prints: 0
upvoted 0 times
...

Save Cancel