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 CPP Exam - Topic 9 Question 49 Discussion

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
A) 144 0144
B) 144 0x64
C) 0x144 0144
D) 0144 100
E) compilation error

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
7 months ago
I disagree, it should be 0x64 for the second one.
upvoted 0 times
...
Mose
7 months ago
Wait, why is it 144 and not 100?
upvoted 0 times
...
Dalene
7 months ago
I think it should show the base for the second output.
upvoted 0 times
...
Sheridan
7 months ago
Definitely not a compilation error!
upvoted 0 times
...
Gabriele
8 months ago
Outputs 144 0144
upvoted 0 times
...
Roslyn
8 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
8 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
8 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
8 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
8 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