0

Just a simple question regarding C language

I was writing a C program to add two numbers and my program worked without putting return 0; at the end of the code So is that return 0; always a must to put in any C code and what does it do

31st Jul 2022, 8:13 PM
Kushal Sharma
Kushal Sharma - avatar
2 odpowiedzi
+ 1
return 0 in the main function indicates to the operating system that the program ended successfully. C is very liberal in what it accepts as the main function. So you: dont have to specify the correct arguments; dont have to return something even though it has a return type... But these are only true for the main function. Every other function has to strictly return a value of the specified return type. The return in main today is not as important as it used to be. The OS cleans everything anyways and there is little difference in the reponse form the OS depending how the program exited. But it can be helpful for chaining programs together. For example you might want to execute a program as part of a shellscript and choose different routes depending on the return value of the program.
31st Jul 2022, 8:42 PM
Erarnitox
Erarnitox - avatar
0
Thanx alot
31st Jul 2022, 9:00 PM
Kushal Sharma
Kushal Sharma - avatar