Results 1 to 6 of 6

Thread: Differences between int main() and int main(void)

  1. #1
    Join Date
    May 2011
    Posts
    55

    Differences between int main() and int main(void)

    Hello to all who visit this site regularly. A warm welcome from my side to all of you. I am a student and have got some assignments to do. I have a question which I am not able to get what it is. So I am here to seek some help from you all experts. So please help me out. The question is, Is there any difference between int main(void) and int main()?

  2. #2
    Join Date
    May 2009
    Posts
    527

    Re: Differences between int main() and int main(void)

    First of all welcome to you on our site. You can feel free to post your queries over here because this forum is regularly visited by the experts in the various field and you have high possibilities that your problems would be solved out. Really speaking there does not lie a great difference between the two, but normally we should use parameterized main because it serves better than the non parameterized.

  3. #3
    Join Date
    Apr 2009
    Posts
    488

    Re: Differences between int main() and int main(void)

    Hello dude. We welcome you. You don’t need to think too much on this as there is not much difference between the two. But for your knowledge you should know that compiler may generate some errors/warnings if you declare the arguments in the main and do not use it. So to be on safer side if your program doesnot have command line argument than use the normal main() only and do not go for the arguments.

  4. #4
    Join Date
    May 2009
    Posts
    539

    Re: Differences between int main() and int main(void)

    Yes there does not lie a great difference between the two as they both would work fine. Different people use different ways of writing the programs, so in short you can say that both will run fine without causing an error. But you should know that when you donot specify a void in the argument then you need to give a return type at the end of the code so that it works fine or else error will be generated.

  5. #5
    Join Date
    Apr 2009
    Posts
    569

    Re: Differences between int main() and int main(void)

    Yes here you will understand more clearly.
    Example of int main()
    #include<stdio.h>
    int main()
    {
    /*code*/
    return 0;
    }

    Example of int main(void)
    #include<stdio.h>
    int main()
    {
    /*code*/
    }

  6. #6
    Join Date
    May 2009
    Posts
    529

    Re: Differences between int main() and int main(void)

    Being a programmer you should have some basic knowledge that what things are written for what. I the code nothing is useless. Everything is present for some of the reason or the other, nothing is waste. Void is the return type. Every block of code returns something or the other. So it needs to be present over there. If you don’t mention also with the main than you should write the return 0 at the end of the block otherwise an error will be generated resulting in no output. Also note that int is also a return type and this should be used when the code returns the integer value.

Similar Threads

  1. Which CPU socket should I use in the main rig?
    By Mattabesic in forum Hardware Peripherals
    Replies: 4
    Last Post: 08-12-2010, 10:31 AM
  2. Java keywords public static void main (String args[])
    By Bhim in forum Software Development
    Replies: 4
    Last Post: 06-08-2010, 08:09 PM
  3. Restart main in java
    By cyber-noob in forum Software Development
    Replies: 4
    Last Post: 24-11-2009, 05:31 AM
  4. My main hdd is full, what to do?
    By Bull50 in forum Hardware Peripherals
    Replies: 3
    Last Post: 11-02-2009, 10:40 AM
  5. main differences between office 2000 to office 2007
    By Dhananjay in forum MS Office Support
    Replies: 1
    Last Post: 31-01-2008, 10:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,585,719.64805 seconds with 17 queries