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:
Suggested Answer: C
Get Premium CPP Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
20 comments · newest first
AR
Arlean
7 days ago
Same here, it's straightforward.
OM
Omer
12 days ago
I feel confident about this question.
LO
Louvenia
17 days ago
Yes, definitely!
DE
Demetra
22 days ago
So, B is the right choice then?
AR
Arlean
27 days ago
Exactly, it should convert 64 to decimal.
OM
Omer
1 month ago
A doesn't consider hex conversion.
DE
Demetra
1 month ago
But what about A) 64 100?
AR
Arlean
1 month ago
I agree with B too.
LO
Louvenia
2 months ago
Because 64 in hex is 100 in decimal.
OM
Omer
2 months ago
Why B?
LO
Louvenia
2 months ago
I think it will be B) 100 256.
YE
Yen
2 months ago
Not sure about that, seems a bit off to me.
MA
Margot
2 months ago
The input is read as hex, so it makes sense.
BE
Becky
2 months ago
Wait, why does it show 0x100? I thought it would just be 100.
CU
Curtis
3 months ago
Totally agree, that's the hex representation!
TI
Tiera
3 months ago
It will output 0x64 0x100.
JE
Jesse
3 months ago
I guess the output will be in hexadecimal, but I'm confused about whether it will show both numbers or just one.
MA
Margart
3 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.
LU
Luisa
3 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.
WI
Winifred
3 months ago
I think the input is read as hexadecimal, so 64 should be 100 in decimal, right?