Sep 5, 2016 at 2:24pm UTC
Hi guys I came across an exercise which I have no idea about. Here I have to determine the console outputs for the couts and if the function do_something(92) is called :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
string do_something(unsigned int input) {
unsigned int &i = input;
const char * vect = "0123456789ABCDEF" ;
string temp = "" ;
cout << "input=" << input << ", i=" << i << endl;
while (i > 0) {
short index = input % 0x10;
temp = *(vect + index) + temp;
input = input / 0x10;
cout << "input=" << input << ", index=" << index << endl;
}
cout << "input=" << input << ", i=" << i << endl;
return temp;
}
Could someone please explain what is going on here ? Thanks!
Last edited on Sep 5, 2016 at 2:33pm UTC
Sep 5, 2016 at 2:31pm UTC
Why not slap a main() function onto it, compile and run the code and see what you get?
Sep 5, 2016 at 2:32pm UTC
i do know the answers, but I really do not understand them. So it would be really wonderful if someone could explain them to me?
Sep 5, 2016 at 4:18pm UTC
Firstly I agree with what dhayden says... why don't you just compile it
Also you could comment on the lines you don't understand, that would help us to help you...