Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Entry Point of a Program | Getting Started
C++ Introduction
course content

Course Content

C++ Introduction

C++ Introduction

1. Getting Started
2. Variables and Data Types
3. Introduction to Operators
4. Introduction to Program Flow
5. Introduction to Functions

bookEntry Point of a Program

Every C++ program must have a main() function. The syntax of it looks like this:

  • int main(): the starting point of a program. It's called the main function, and it's where the program begins executing;
  • { }: curly braces define a block of code. Everything inside these braces belongs to the main function and is part of the program's logic;
  • return 0;: marks the end of the program and indicates that it ran successfully. The 0 means everything went well. If there were issues, this value might be different in the output.

Note

The return 0; statement is optional at the end of the main function. If omitted, the compiler will automatically insert it.

What is the purpose of the main() function in a program?

What is the purpose of the main() function in a program?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 3
some-alt