0
Whats the difference bw int main(), void main(),main()
5 Respostas
+ 4
main is the most important function of c,c++,java.
From there it show output. If a arbitrary function is outside of main. It will compile but not show its behavior or output value from that function. (if it not externally used in main function)
int main return integer value.
void main return nothing not even void.
and there is nothing like only main function. You have to define it with data type. Also only main function without data type was valid in C89. But in modern C (C99), this isn't allowed anymore because you need to explicitly tell the type of variables and return type of functions, so it becomes
int main() {
return 0;
}
+ 4
Return does nothing but place a value on the stack, so that calling function can pick it up after the procedure block execution ends. I recommend reading a book on computer architecture. It's worth understanding those things even if you program in a high level language.
+ 1
basically every function must have return type.
when you use 'int main' it returns int value. so main must have to return any Integer. if not than compiler shows error.
when you use 'void main' it returns nothing. so main will not return anything. in this case return statement is optional. but you can write only return to terminate the execution of function.
when you use 'main' it means default return type which is int. so main is same as 'int main'.
in professional coding practice you must use 'int main' because when your program execute by another software & if there is any error occurred at runtime in your program, the calling program get the error code. when it get '0' means program executed perfectly.
0
what does return mean in simple way
- 1
jb tum do function bnaoge... tb main lgta hai agar void main lgaoge to dushra function pahle function me value pass nhi kr payega