New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPP Exam - Topic 9 Question 49 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 49
Topic #: 9
[All CPP Questions]

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

#include

using namespace std;

int main()

{

cout.setf(ios::oct, ios::basefield);

cout<<100<<" ";

cout.setf(ios::showbase);

cout<<100<<" ";

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Luke
4 months ago
I disagree, it should be 0x64 for the second one.
upvoted 0 times
...
Mose
4 months ago
Wait, why is it 144 and not 100?
upvoted 0 times
...
Dalene
4 months ago
I think it should show the base for the second output.
upvoted 0 times
...
Sheridan
4 months ago
Definitely not a compilation error!
upvoted 0 times
...
Gabriele
4 months ago
Outputs 144 0144
upvoted 0 times
...
Roslyn
5 months ago
I feel like there might be a compilation error because of the way the `setf` function is used, but I can't quite remember if that's correct.
upvoted 0 times
...
Olive
5 months ago
I practiced a similar question where we had to set different formats, and I think the output should be 144 for the first one and something with a prefix for the second.
upvoted 0 times
...
Mabel
5 months ago
I remember something about showing the base with `ios::showbase`, but I can't recall if it applies to the first output or the second one.
upvoted 0 times
...
Casey
5 months ago
I think the first output should be in octal since we set it to octal format, but I'm not sure what the actual value will be.
upvoted 0 times
...
Ozell
5 months ago
Okay, I've got this. Documentary evidence is definitely required, so I'm going with option A. Can't go wrong with the basics.
upvoted 0 times
...

Save Cancel