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
Louvenia
3 days ago
Because 64 in hex is 100 in decimal.
upvoted 0 times
...
Omer
8 days ago
Why B?
upvoted 0 times
...
Louvenia
13 days ago
I think it will be B) 100 256.
upvoted 0 times
...
Yen
18 days ago
Not sure about that, seems a bit off to me.
upvoted 0 times
...
Margot
23 days ago
The input is read as hex, so it makes sense.
upvoted 0 times
...
Becky
28 days ago
Wait, why does it show 0x100? I thought it would just be 100.
upvoted 0 times
...
Curtis
1 month ago
Totally agree, that's the hex representation!
upvoted 0 times
...
Tiera
1 month ago
It will output 0x64 0x100.
upvoted 0 times
...
Jesse
1 month ago
I guess the output will be in hexadecimal, but I'm confused about whether it will show both numbers or just one.
upvoted 0 times
...
Margart
2 months 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
2 months 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
2 months ago
I think the input is read as hexadecimal, so 64 should be 100 in decimal, right?
upvoted 0 times
...

Save Cancel