- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements