The main method is where the bulk of your code goes - it’s like the body paragraph of an essay. There are two ways to declare the main method:
- The common version
As you can see, the parentheses are empty, meaning that there are no arguments.
int main(){ }
- The command line version
Here, in the parentheses, we can see the arguments. At this level, you don’t need to be concerned with this, but you would need to accept the arguments from an external method, most likely a global variable.
int main(int argc, char * argv[]){ }
In the main method, int is the return value. This means that after you write your code you must return an integer. The integer returned does not have to mean anything in your code, you can simply return 0.
Next Section
2.2 Breaking out of the main methodCopyright © 2021 Code 4 Tomorrow. All rights reserved.
The code in this course is licensed under the MIT License.
If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.