Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3999416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:39:16+00:00 2026-05-20T07:39:16+00:00

Possible Duplicate: C void arguments I just started with C and I can’t find

  • 0

Possible Duplicate:
C void arguments

I just started with C and I can’t find answer to this…

Is there any difference between

int foo() { }

int foo(void) { }

Which should I prefer and why?

Note that this question also goes for: int main. Should it be: int main or int main(void) when I don’t want any command-line arguments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:39:16+00:00Added an answer on May 20, 2026 at 7:39 am

    The two canonical forms of main are, according to the standard (see C99 section 5.1.2.2.2 “Program startup”):

    int main (void);
    int main (int argc, char *argv[]); // or equivalent such as char **argv
    

    Others are specifically allowed but those are the required ones.

    As to the preferred form between fn(void) and fn(), I prefer the former since I like to explicitly state that there are no parameters.

    There is also a subtle difference. C99 section 6.7.5.3 “Function declarators”, paragraph 10, states:

    The special case of an unnamed parameter of type void as the only item in the list
    specifies that the function has no parameters.

    Paragraph 14 of that same section shows the only difference:

    An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.

    In other words, it means the same as void in the function definition but does not mean that in a standalone declarator (i.e., the prototype). int fn(); means that no information on the parameters is yet known but int fn(void); means there are no parameters.

    That means that:

    int fn();
    int fn (int x) { return x; }
    int main (void) { return fn(0); }
    

    is valid but:

    int fn(void);
    int fn (int x) { return x; }
    int main (void) { return fn(0); }
    

    is not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference between void main and int main? Why is void main() {
Possible Duplicate: Difference between void main and int main? Alright, so I'm using bloodshed
Possible Duplicate: objective c difference between id and void * While reading through NSZone.h
Possible Duplicate: What is System.Void? I have no practical reason for knowing this answer,
Possible Duplicate: objective c difference between id and void * why most of the
Possible Duplicate: objective c difference between id and void * For example, an UIView
Possible Duplicate: What should main() return in C/C++? Difference between void main and int
Possible Duplicate: Hide/Show Navigation & Tool Bar on tap This is the void I'm
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.