Main Function in C Programming

Main Function in C Programming post thumbnail image

In this post we will read about main function and understand how main() function is used in C programming and how we define main function in C programs.

Whenever we do any work in our life, then most of us know from where we have to start the work and where to end it.

Similarly, when you compile and run C programs, the main () function present in your programs acts as the entry point and exit point for the compiler and operating system.

The main function in C programming is a built-in function whose only prototype is predefined by the C compiler and its body (functionality) is defined by the programmer.

Most of the important code (statements) of your C programs comes inside the body of main() function ie curly braces { } and these statements are executed one by one.

There are many prototypes of declaring the main() function in C language. Here I am telling you the 2 most common declarations.

The first method is easier to write but the standard method is not. The second method is the standard and recommended method, so I would suggest that you use the second method.

main() function non-standard declaration:

Main Function in C Programming
Main Function in C Programming

main() function standard declaration:

Main Function in C Programming
Main Function in C Programming
Main Function in C Programming
Main Function in C Programming

You can also read: Compile and Run C Program

What is the meaning of return 0 in main function?

return 0 is written before the closing curly braces } in the standard declaration of the main() function. Let us understand what is the meaning of return 0 in main function.

When the C program reaches the return statement without any error, then 0 value is returned to the operating system from there, which means that the C program has been successfully run.

You can use any integer value other than 0 with the return statement, but you have to find out what that value means for the operating system, as 0 means the program has successfully run.

I hope that you have liked this post. If you liked the post, then please share it with your friends and relatives and you can send your suggestion in the comment box below or email me at praveen171086@gmail.com.

You can also visit my Hindi YouTube Channel.

mm
Avinash Singh

I am Avinash Singh, a software engineer from the profession and have been working in the IT industry since 2009. I live in Barabanki district of Uttar Pradesh in India and completed intermediate in 2001 from Ram Sevak Inter College, a UP Board school. After inter I completed my professional degree (BCA & MCA) from Indira Gandhi National Open University, Delhi in 2008 and along with it I did many certifications to keep my knowledge up to date and the next year I started a software development company E – Vision Technocraft Pvt Ltd.

Leave a Reply

Your email address will not be published.

Related Post