The Main Method
The main method is a place where you can execute lines of code and make calls to other functions used in your program. Essentially, it’s where all the coding action happens, especially for the more basic types of programs. In C, the syntax of the main method looks like this:
int main (void) { //code }
The “int” is in the place of the return type of the method. This means that in this example, I can only return an integer. You do not have to return anything in the main method, though the same does not apply for other methods. Returning is what the method’s value/result is when the function is called.
The “void” is where the parameters of the method go. Void means that there are no parameters in this method.
Remember, in order to use the main method in your program, you must include the C Standard Library at the top of your program. Head over to lesson 1.2 if you need a refresher on importing the standard library.
Copyright © 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.