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

Posted by Haydee on May 31, 2022 at 04:14 AM

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:

Suggested Answer: A

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
10 comments · newest first
LU
Luke 11 months ago
I disagree, it should be 0x64 for the second one.
MO
Mose 11 months ago
Wait, why is it 144 and not 100?
DA
Dalene 12 months ago
I think it should show the base for the second output.
SH
Sheridan 12 months ago
Definitely not a compilation error!
GA
Gabriele 12 months ago
Outputs 144 0144
RO
Roslyn 1 year 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.
OL
Olive 1 year 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.
MA
Mabel 1 year 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.
CA
Casey 1 year 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.
OZ
Ozell 1 year 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.
0/2000 characters

Save Cancel