+ 2
Difference b/w "int main ()" and "void main()"
difference b/w "int main ()" and "void main()" or it is same I'm confused in it
6 Réponses
+ 2
"void main()" is illegal C++!
(Your compiler will know what you meant and ignore it though)
+ 9
Words from the creator himself.
http://www.stroustrup.com/bs_faq2.html#void-main
+ 6
In C++, the main returns a 0 or 1 (exit codes for success/failure), and that's why you utilize int main for that purpose. That exit code is often utilized by the OS to generate an error if needed.
If you use void, it doesn't return a value at all, and thus wouldn't return an exit code for success/failure status. However, as Schi pointed out, void main() is illegal and has never been a part of C/C++ languages.
+ 3
you mean void main () is illegal
+ 2
thx
+ 1
void is used when you don't need to return any values from function. int is used to return a int value from function.
i.e.
int sum( int a, int b ){
return a+b;
}
void sayHello(){
cout<<"Hello!";
}
char, float and double can also be used in any user-defined function in place of int depending on what type of value you want to return.
void main(){} returns no values
int main(){} returns 0 which is int data type
you cannot use char, float and double for main() function