top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Difference between int main() and int main(void)?

+2 votes
472 views

Many a times in C we get these two type of main function one had void as parameter one has none. Now the question is what is the difference between these two?

posted Jun 27, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

There is no difference between function having void as a parameter and a function having nothing as a parameter both of the function are design to accept nothing i.e no value .if a function which is does not accept any value by default it is void only

answer Jun 27, 2014 by Swetabh Srinath
in C, int main() can be called with any number of arguments, but int main(void) can only be called without any argument. Although it doesn’t make any difference most of the times, using “int main(void)” is a recommended practice in C.
+1 vote

Technically there is no difference between int main() and int main(void). In both the cases we can not have any parameter but recommended practice is to use void when there is no command line parameter. Check the following list of parameters passed to the main function.

1. int main ( void ) /* No argument and You have to mention void */

2. int main ( int argc, char *argv[] ) /* Two argument - 
                                          argc: argument count, 
                                          argv: contains the list of parameters */

3. int main ( int argc, char *argv[], char **env ) /* Three argument -
                                                   argc: argument count, 
                                                   argv: contains the list of parameters 
                                                   env: environment variables */
answer Jun 28, 2014 by Salil Agrawal
Similar Questions
+2 votes

If I correct , by default main () function has integer return type.
I want to know what happens in the system internally when its return type gets changed from integer to void ?

+4 votes

What will be the output of this code?

 void main(){
       int i=320;
       char *ptr=(char *)&i;
       printf("%d",*ptr); 
    }
+1 vote

What is the difference between

public static void Main()

and

private static void Main()

in C#?

...