Cpp - Function Recursive function

Introduction

A function that calls itself is a recursive function.

The following code Demonstrates the principle of recursion by a function, which reads a line from the keyboard and outputs it in reverse order.

Demo

#include <iostream> 
using namespace std; 

void getput(void); 

int main() /*from   w ww  . j a v  a 2 s  .  c o m*/
{ 
    cout << "Please enter a line of text:\n"; 
    getput(); 
    cout << "\nBye bye!" << endl; 
    return 0; 
} 

void getput() 
{ 
    char c; 
    if( cin.get(c)  &&  c != '\n') 
        getput(); 
    cout.put(c); 
}

Exercise