Skip to content Skip to sidebar Skip to footer

Main Function in C++

In C++, the main() function is a very important function. It is responsible for starting a program, controlling the flow through the program, and providing a place in the program for error reporting.

What is Main() Function?

The main() function is the central entry point to a C++ program. It has two main jobs. First, it starts up the program’s execution and handles basic setup. Second, it provides a place to put functions that perform I/O or manage memory, handling any programs that will run simultaneously. The following is an example of what would go in the main():


return_type main(){

//function body



int main(){

//function body

return 0 ;
The most preferred way is using int main().

In above example

  • int main(): int is the preserved keyword here, and int main() is an entry point for a program to be executed. It is intended to be used by the operating system when creating a new process or launching an existing process. Using int in front of the main function means it will return some value as “return 0” at the end of the program. 0 is the standard for the “successful execution of the program.”
  • function body: In the function body, we write the program we want to execute here and can call the function located outside the main functions here.
  • return 0: When a return 0 statement is encountered, the program will exit. A function-entry statement can follow an end-of-function statement. In return 0, 0 is the standard for the “successful execution of the program.”


So, that was all about the main function in c++, and you got all the information about it. Suppose you understood and comprehended this blog properly. Well done. You’re getting advanced daily. If, in any case, you’re finding it difficult, you can let us know in the comments & contact us. Besides, if you’ve any doubts, you can post them in the comments. Don’t worry; our geeks will surely get your doubts cleared soon.

Similarly, you must also know that GeekonPeak has just begun and is looking for some loyal supporters so we, the new-gen geeky friends, can grow and create more comprehensive and easy-to-grasp courses for you (for free). Follow us on FacebookInstagram & Twitter as well. Also, don’t miss our newsletter subscription. We provide exclusive blogs, tips, tricks, and advice to program efficiently and market smartly. We also promote some of our partners with excellent experiences to share with you. Until next time 🙂

Leave a comment

Sign Up to Our Newsletter

Be the first to know the latest updates