My assignment is as follows...

Create a program called part4.cpp containing a recursive function that accepts a pointer to a null-terminated string as its argument, and prints the string in reverse order.
Demonstrate the function by calling it from the main function with a string that has been provided by the user. In other words, you will prompt the user to enter a string and the program will disply the string backward.

I'm a little confused as to what a null terminated string really is. Can someone who understands clarify for me what exactly I need to do in this program?


First off, in C, there is no built-in string data type. Therefore, string is represented in an array of characters. The null terminator depicted by a \0 (backslash zero). It is the way of telling where the string ends.

Recursion means a function keeps calling itself until the termination case occurs. You can read more about this if you are not sure what recursion is all about.

Here's the logic:
Implement a function that takes in a pointer to null-terminated string, then check if the pointer's value is null. If it is, return without doing anything. If it is not, call itself again by passing in the pointer to the next character in the string. Directly after this line of code, remember to print out the pointer's current value (this is important to ensure that your characters are printed in reverse order)

This article has been dead for over six months. Start a new discussion instead.