Interview Question

Interview(Student Candidate) Boston, MA

Write an integer-to-string function in C++.


Interview Answer

1 Answer


The answer involved dividing the integer by successively smaller amounts, relying on the fact that integer division floors the quotient, to "grab" characters corresponding to the numbers starting from the left and going to the right. There had to be three cases, one in which the number was negative, one in which it was zero, and one in which it was positive. Leading zeros should not be added to string.

Interview Candidate on May 1, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.