+ 37

What's the difference between void main() and int main()?

13th Jul 2015, 4:44 AM
mihir mistry
mihir mistry - avatar
102 Réponses
+ 18
on the website of the author of c++ it's said in the FAQ that void main is not c++. So the best is to avoid it, even if visual studio allows that... source : http://www.stroustrup.com/bs_faq2.html#void-main
29th Jul 2016, 5:45 PM
Dorian
+ 81
Void means the function will not return anything. Int main means it will return an integer
23rd Oct 2015, 4:41 PM
BitVX
BitVX - avatar
+ 67
Windows expects no return value, so the void main() is used. Unix based operating systems expects 0 if the program finished succesfully and any non-zero value if the error occured, hence int main() is used.
10th Jul 2016, 7:17 PM
Борис Кот
Борис Кот - avatar
+ 17
When a function is void this means it returns nothing. If it is written int before the name of the function, this means it should return an integer at the end.
25th Oct 2016, 7:25 PM
Remmae
Remmae - avatar
+ 9
Let me clear this very logically .... For any function consider this rule - ////////////////////////////////////////////// return_type function_name(arguments) { block of codes } #arguments are optional ////////////////////////////////////////////// Now come to the point 1. void main( ) void - void is the return data type and in this case no value is being returned, so void is used. main - the name of function ( ) - every function has these parentheses for passing arguments but here we don't have any arguments which is optional 2. int main( ) int - return data type , it means integer is being returned. main - the name of function ( ) again you know ... 😊 3. void add(2,4) void - return data type , here no value is being returned. add - the name of function (2,4) - 2 and 4 are arguments to be passed. 4. int add(2,4) int - return data type , it means integer will be returned. add - the name of function (2,4) - you know the parentheses and 2,4 are two arguments which are passed to function. 1. No return value , no argument 2. With return value , no argument 3. No return value , with argument 4. Return value , with argumen I hope all is clear now .... don't get confuse in just void main( ) and int main( ) , they are just function like every function ..... 👍👍👍
14th Jan 2017, 6:21 PM
AlamSirji
AlamSirji - avatar
+ 6
void main() function does not returns any value and int main or xxx main where xxx are the data types returns the integer value or the xxx value.
25th Nov 2016, 1:05 AM
Gupta Gaurav
Gupta Gaurav - avatar
+ 6
One of the highest-voted answers reads "Windows expects no return value". This doesn't mean they're not used everywhere. Error CODES (exit reasons, captured by the OS) are more PORTABLE than messages (which can be printed to files, consoles, stdout, in different languages, misspelled or even ignored) and are often silently captured/processed. Linux stores exit codes in the variable $?. Windows stores the result in %ERRORLEVEL% and PowerShell uses $? (for success/fail) and $LASTEXITCODE for more detail (the exit code) It greatly supports communication and it's everywhere in Windows (https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx -- and that's just the first 500...of the 16,000 in that list). Don't skip this. http://stackoverflow.com/a/204483/3981745 "The return value for main should indicate how the program exited. Normal exit is generally represented by a 0 return value from main. Abnormal termination is usually signalled by a non-zero return but there is no standard for how non-zero codes are interpreted. Also as noted by others, void main() is explicitly prohibited by the C++ standard..."
1st Dec 2016, 12:25 PM
Kirk Schafer
Kirk Schafer - avatar
+ 5
whatever is written before main() , tells about the return type of main(). 'void' means main() will not return anything. int means main () will return a integer value.
24th Nov 2016, 1:18 PM
vijayalakshmi
vijayalakshmi - avatar
+ 5
int will return a value(integer).In this case (return 0;) is also used. void will not return anything!!!!!!
26th Nov 2016, 10:39 AM
Sreerag V S
Sreerag V S - avatar
+ 4
void keyword is placed when that function does not return value to any other calling function . in this case void main will not return any value while in int main...main function will return an integer value and hence in main function we will have to include return keyword with 0 value as main function is the starting and ending point in the process of execution of a code...
29th Nov 2016, 12:47 PM
KUMAR SHASHWAT
KUMAR SHASHWAT - avatar
+ 4
in void no value is returned but in int value returned is of type integer
27th Dec 2016, 6:07 PM
FARZA
FARZA - avatar
+ 3
void main() means we have to give back no value where as int main() means it will expect an integer value 0 or 1 at last of the program.0 means that the program ends .so return 0 is used to tell the compiler that program ends
24th Nov 2016, 3:30 PM
Future Tech
Future Tech - avatar
+ 3
void main : as the word void suggest nothing or blank. The function type implies that this particular function would not return any value. int main: Here the function type is int . So it is compulsory for the function to return any int value.
24th Nov 2016, 4:25 PM
Himanshu Carpenter
Himanshu Carpenter - avatar
+ 3
void basically means no value or return type. when you use void main() the function does not have a return type or value. int is a keyword for integer type data types, so when you use into main(), you're returning a value of integer type which can be acceded by other user defined functions.
24th Nov 2016, 4:27 PM
Abdul Hakeem
Abdul Hakeem - avatar
+ 3
void main doesn't return anny thing, but int main it return an integer value
24th Nov 2016, 5:13 PM
kamelia ait yahia
kamelia ait yahia - avatar
+ 3
void you return nothing and int return integer
24th Nov 2016, 10:42 PM
Francisco Javier Coenda
Francisco Javier Coenda - avatar
+ 3
yeah, void is won't return and int will return an integer, but sometime you learn OOP, void will use as setter (mutator) funct, and int or other data type will use as a getter(acessor) funct..
27th Nov 2016, 1:23 AM
Mafmudin (ig:tw:: @mafmudin)
Mafmudin (ig:tw:: @mafmudin) - avatar
+ 2
void means that the main() function will not return any value whereas int means that main() will return a value.
31st Oct 2016, 4:24 AM
OmGupta
OmGupta - avatar
+ 2
The major difference between void main() and int main() is that,the void main () does not return any value... While the latter i. e. int main() returns value of integer type
26th Nov 2016, 8:44 AM
Vaibhav Borhade
Vaibhav Borhade - avatar
+ 2
void main has not meaning in c++. The main function must always return int. For any other function void means that it does not return anything.
26th Nov 2016, 1:44 PM
Ernaso Kerbizi
Ernaso Kerbizi - avatar