+ 1
Why we use datatypes before the main() function. What is difference among int main() and void main() and float main()
C language
3 Respostas
+ 2
When C was created the most commonly used OS was UNIX. In UNIX (and generally in OS's) it is important whether some proces failed or did their job correctly. For kernel to get that info, every proces needs to return its status after finishing / being interrupted. It was 0 if everything went good and 1 (usually) when it failed. That's why in C you use
int main() {
...
return 0; }
When the program fails you can see its output status as a non-zero value ;)
When it comes to float - we don't need to use that much memory to represent just 2 states
void - we won't get any value so we won't know wheter our program finished well or failed
+ 1
It’s mean the function will return the datatype that you specificed it
+ 1
A function can return something, the type of the thing a function returns is commonly termed as function's return type. This applies also for main() function. Although the C standard suggests main() function to return `int`.
More details here ...
https://en.cppreference.com/w/c/language/main_function