Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why we use int main?

+4 votes
asked Mar 22, 2023 by Chandan Kumar (160 points)

8 Answers

+4 votes
answered Mar 23, 2023 by Rubab Qaiser (220 points)

int is the data type of the return value and main is the function which will return an integer value.​

+5 votes
answered Mar 23, 2023 by Peter Minarik (86,200 points)

That is the main entry point of the application unless told otherwise to the compiler. :)

If you do not have an entry point, the compiler will not know where the execution of your program begins.

The int return type also means that your program will return with a number that is typically used for error signaling where 0 means no error.

0 votes
answered Apr 6, 2023 by mishradivyasish (180 points)
We use int main because it is the basic structure of any programing language.We require main function to call other function within it.
0 votes
answered Apr 11, 2023 by Abhiram (150 points)
because int main to reference an integer data type
0 votes
answered Apr 13, 2023 by HARI KRISHNA (140 points)
int main is a main function in our program and the int is nothing but the integer datatype

shortly we denoted starting point of the program
0 votes
answered Apr 14, 2023 by Anurag Singh (140 points)
We use int main because when a program is started executing, so the compiler finds the int main function very first and the execution of program starts from int main
It's an entry point of a program.
Int main returns some value it indicates that program has been executed and it's come to the end and it's gonna get terminated by compiler


Hope info helped
0 votes
answered Apr 17, 2023 by Anmol Upadhyay (220 points)

int main represents that the function returns some integer even '0' at the end of the program execution. '0' represents the successful execution of a program. int main(void) represents that the function takes NO argument. Suppose, if we don't keep void in the bracket, the function will take any number of arguments.

0 votes
answered Apr 18, 2023 by EklavyaDW (230 points)
As soon as you trigger the button to turn on the CPU it starts machine and loads operating system aka OS. OS then loads/wakes up the drivers/hardwares and check if everyone is fully awake or not if not it throws/displays error on screen and asks user to do something about it. OK! so after waking up everyone in system, OS is ready and running fine. Now suppose you write a program in c and presses the run button after building it, what run does is it loads your programme in memory, data segment, stack which is part of OS memory, the instructions are being sent to OS that this guy has some input and needs answer. OS system does the calculations (ALU) and sends it back to user. Now all this happens with OS level but user has this impression, that his programme is doing this, catch is OS too can fail sometimes, due to some interrupts, or some errors may occur, that time OS throws an error which is non zero value always. 0 for successful execution.

We know that main() is system declared but user defined function i.e. we define this function. so for OS the entry point is main() but internally whatever written inside main is being executed by OS only. if our main() returns 0 it means your execution is successful and failed otherwise.

That's the very reason we return value in main().

Hope you got your answer now! :)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...