What's the difference between void main() and int main()? | SoloLearn: Learn to code for FREE!

+35

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

7/13/2015 4:44:00 AM

mihir mistry

102 Answers

New Answer

+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

+81

Void means the function will not return anything. Int main means it will return an integer

+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.

+16

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.

+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 ..... 👍👍👍

+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.

+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..."

+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.

+5

int will return a value(integer).In this case (return 0;) is also used. void will not return anything!!!!!!

+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...

+4

in void no value is returned but in int value returned is of type integer

+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

+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.

+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.

+3

void main doesn't return anny thing, but int main it return an integer value

+3

void you return nothing and int return integer

+3

void means that return type is nothing, none whatsoever. int means that return type of particular method will be intefer

+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..

+2

void means that the main() function will not return any value whereas int means that main() will return a value.

+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