C++ Recursion
w3hello.com logo
C++ Basics
What is C++
Introduction to C++
C++ Installation
Comments in C++
C++ Variables
C++ Pointer Operators
C++ Data Types
C++ Variable
C++ Loop Types
Discuss C++
C++ While Loop
C++ do while loops
C++ while loops
C++ Increment and Decrement Operators
C++ For Loop
C++ if Statements
C++ nested if statements
C++ Comments
C++ for loops
C++ do...while loop
C++ if-else Statements
C++ switch
C++ if...else statement
C++ OOPs Concepts
Operators in C++
C++ Operators
C++ Loops
C++ Member (dot & arrow) Operators
C++ Basic Input Output (cin, cout, endl)
Operators Precedence in C++
C vs C++
C++ switch Statements
C++ if-else
C++ Exception Handling
Constructors and Destructors in C++
C++ File and Stream
C++ Continue Statement
C++ Object Oriented
C++ Arithmetic Operators
C++ Pointers
Pointers in C++
C++ try-catch
C++ Enumeration
ANSI C++ New Features
C++ Recursion
C++ Modifier Types
C++ Break Statement
C++ ios_base init
C++ Compute the Sum and Average of Two Numbers
C++ Preprocessor
C++ Class Constructor and Destructor
Matrix Multiplication in C++
C++ Strings
C++ Basic Input/Output
C++ Qualifiers and Storage Classes
C++ Assignment Operators
Data Abstraction in C++
C++ Class Access Modifiers
C++ Structs
Interfaces in C++ (Abstract Classes)
String Manipulation in C++
C++ References
C++ Date and Time
C++ Useful Resources
C++ ios_base openmode
C++ Aggregation
C++ Introduction
Call by value and call by reference in C++
C++ ios_base fmtflags
C++ Templates
C++ Namespaces
C++ Fstream fpos
C++ ios_base event
Returning values by reference in C++
C++ Polymorphism
C++ nested loops
C++ Constants
C++ Casting Operators
C++ Objects and Classes
C++ static
Storage Classes in C++
C++ ios_base seekdir
Data Encapsulation in C++
C++ Null Pointers
C++ Inheritance
Armstrong Number in C++
C++ switch statement
C++ Encapsulation
Pointer to C++ Classes
C++ Files and Streams
C++ Interfaces
Data Types in C++
Variable Scope in C++
C++ Destructor
C++ Manipulators
Static Members of a C++ Class
Fibonacci Series in C++
C++ this Pointer
C++ Object Class
Polymorphism in C++
C++ Basics
Previous : ANSI C++ New Features Next : C++ Modifier Types

C++ Recursion


When function is called within the same function, it is known as recursion in C++. The function which calls the same function, is known as recursive function.

A function that calls itself, and doesn't perform any task after function call, is known as tail recursion. In tail recursion, we generally call the same function with return statement.

Let's see a simple example of recursion.

C++ Recursion Example

Let's see an example to print factorial number using recursion in C++ language.

Output:

Enter any number: 5
Factorial of a number is: 120

We can understand the above program of recursive method call by the figure given below:

CPP Recursion 1
Previous : ANSI C++ New Features Next : C++ Modifier Types
© Copyright 2018 W3Hello Publishing Limited. All rights reserved.
Contact us | Sitemap