+ 4
Difference between int main and void main?
17 Answers
+ 9
int and void are both variable classes. Int is an integer, void is literally nothing. A function named int function returns an integer to the caller, void function at the same time doesn't return anything. I suppose, meanwhile not completely sure that void main is NOT a valid function in C++ for most IDE and architecture. Arduino, for example, using it, because there is no caller of main routine.
+ 7
int main returns a value(typically you see return 0 at the end of a main function)
void main doesn't return a value (hence the name "void" , since void means nothing)
This is what i mean:
int main()
{
// Code here
return 0; // returning 0 tells the computer stop, and also says that the
// program has run successfully. You can also do return 1, or -1
// but they have different meanings
}
void main()
{
// Code here
// Returns nothing, since it's a void function
}
+ 3
int main returns a variable when main function run while void main does not...
like
if we write
void display (c)
{
cout <<''multiplication is:''<<c;
}
int main()
{
int a=10;
int b= 10;
int c=a*b ;
return c;
void display ();
}
and in case if made void main then
void main()
{
int a=10;
int b= 10;
int c=a*b ;
cout <<''multiplication is:''<<c;
}
+ 2
Pls ans with a example
+ 2
void noanswer ()
{
//program code here
return 0;
}
int answer ()
{
//program code here
return 1;
}
int main ()
{
std::cout << " Return of void: " << noanswer() << std::endl;
std::cout << " Return of int: " << answer() << std::endl;
return 0;
}
After compile, it will return:
Return of void:
Return of int: 1
(I'm on the go, can't test the code.)
+ 2
void gives null value to you and if you are using void main than u shouldn't have to return the value instead of it write getch();
+ 2
int main means the function main has a data type that is int and it will return a integer value.
and void main means the function main has a data type void .and the function main will not return any value.
+ 2
it's return type dude void means nothing will return and int means integer value will return
+ 1
Pls ans??
+ 1
By the way, a code example may help a lot to precisely answer your question.
+ 1
Will not compile because a function call for a return (cout) without a function without return is not valid.
+ 1
very good is your answer
+ 1
int main returns a value but void main dont return a value
+ 1
int main returns a value whereas void main don't return a value its simply nothing that's why after int main we use return statement whereas in void main we don't .
+ 1
why we use getch()
+ 1
int main() can return an error level, whereas void main() doesn't return anything. Also, it is best to use int main() for error checking, and some compilers won't compile runnable programs with void main()
+ 1
just assume main as function.
then int main will need a return value whereas void main does not need any of such things.
that is why when we use int main we have to add a return statement in the last whereas in void main there is no return statement needed.