Challenge: Explain the Main Function()

As a part of the course, a challenge was posed to explain what I think the main function is.

I think it is the entry point into the program, meaning that everything is kicked off from within it.

I’m not sure if every single C++ program, regardless of how complex or simple has a main function hidden away somewhere, or if this is more of a “my first program” construct.

Also, I do not know if there are other functions, that are not the main function, that allow a program to run instead of the main function.

Why do we have expression, declarative, and return statements (in terms of the TripleX game).

Each expression statement is being used to output information to the console.

Each declarative statement is also initializing a variable with a value.

Why do we have include iostream

We include the preprocessor directive iostream so we have access to cout/endl.

Why do we have return 0;

The main method needs to return something. Since int is what we said main would return, we return 0 (arbitrary?)

0 is not arbitrary when returning from the main function. Answer here.

Privacy & Terms