
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Is it legal to recurse into main() in C++?
In C or C++, the main function is like other functions. So we can use the functionalities that are present in some other functions, also in the main function.
In the following program, we will see how the main() is using recursively to print some numbers in reverse order.
Example Code
#include <iostream> using namespace std; int main () { static int x = 10; cout << x-- << endl; if(x) { main(); } }
Output
10 9 8 7 6 5 4 3 2 1
- Related Articles
- Is it possible to give arguments in the main() function in C language?
- How to copy folder contents in PowerShell with –Recurse parameter?
- Is Bitcoin legal in India?
- Difference between void main and int main in C/C++
- Difference between “int main()” and “int main(void)” in C/C++?
- Legal and illegal declaration and initializations in C
- Why is the Main() method use in C# static?
- What is the proper declaration of main in C++?
- How to use the Main() method in C#?
- Differentiate between int main and int main(void) function in C
- What should main() return in C/C++?
- How to call the main function in C program?
- Valid variant of Main() in C#
- Can main() be overloaded in C++?
- Legal Aid in India

Advertisements