3.10. Exercises

1:Write itoh() (Listing 3.3 on page 91) without recursion, and use the same main() program from the chapter. What are the advantages and disadvantages of each version?
2:The recursive version of itoh() (Listing 3.3 on page 91) and Exercise 1 both have void return values because each routine displays the result. Modify the recursive version of itoh() to return a character string pointer to the caller. Use the following program to test your solution.
Listing 3.21. Program with integer-to-hexadecimal conversion
 // itoh2.C - recursive integer-to-hex conversion, returns buffer #include <iostream.h> #include <stdlib.h> int main(int argc, const char *argv[]) { unsigned int num; char *itoh(unsigned int); // returns character pointer if ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.