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 8 Question 124 Discussion

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 64 100?#include #include #include #include using namespace std;int main (){string s;getline(cin, s);stringstream input(s);stringstream output;for( ; !input.fail() ; ){int i;input>>hex>>i;output
C) 100 256 256
A) 64 100
B) 100 256
D) 0x64 0x100
E) 0x100 0x256 0x256

C++ Institute CPP Exam - Topic 8 Question 124 Discussion

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

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 64 100?

#include

#include

#include

#include

using namespace std;

int main ()

{

string s;

getline(cin, s);

stringstream input(s);

stringstream output;

for( ; !input.fail() ; )

{

int i;

input>>hex>>i;

output<

}

cout<

return 0;

}

What will be the result assuming that user will enter following sequence: 64 100:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Margart
4 days ago
This reminds me of a practice question where we had to convert hex to decimal. I feel like the output should be in hex format.
upvoted 0 times
...
Luisa
9 days ago
I'm not entirely sure, but I remember something about how the input stream fails after it can't read a valid hex number.
upvoted 0 times
...
Winifred
14 days ago
I think the input is read as hexadecimal, so 64 should be 100 in decimal, right?
upvoted 0 times
...

Save Cancel