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 797549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:49:26+00:00 2026-05-14T22:49:26+00:00

Many are familiar with the hello world program in C: #include <stdio.h> main ()

  • 0

Many are familiar with the hello world program in C:

#include <stdio.h>

main ()
{
    printf ("hello world");
    return 0;
}

Why do some precede the main() function with int as in:

int main()

Also, I’ve seen the word void entered inside the () as in:

int main(void)

It seems like extra typing for nothing, but maybe it’s a best practice that pays dividends in other situations?

Also, why precede main() with an int if you’re returning a character string? If anything, one would expect:

char main(void)

I’m also foggy about why we return 0 at the end of the function.

  • 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-14T22:49:27+00:00Added an answer on May 14, 2026 at 10:49 pm

    The following has been valid in C89

    main() {
      return 0;
    }
    

    But in modern C (C99), this isn’t allowed anymore because you need to explicitly tell the type of variables and return type of functions, so it becomes

    int main() {
      return 0;
    }
    

    Also, it’s legal to omit the return 0 in modern C, so it is legal to write

    int main() {
    
    }
    

    And the behavior is as if it returned 0.

    People put void between the parentheses because it ensures proper typechecking for function calls. An empty set of parentheses in C mean that no information about the amount and type of the parameters are exposed outside of the function, and the caller has to exactly know these.

    void f();
     /* defined as  void f(int a) { } later in a different unit */
    
    int main() {
      f("foo");
    }
    

    The call to f causes undefined behavior, because the compiler can’t verify the type of the argument against what f expects in the other modules. If you were to write it with void or with int, the compiler would know

    void f(int); /* only int arguments accepted! */
    
    int main(void) {
      f("foo"); /* 'char*' isn't 'int'! */
    }
    

    So for main it’s just a good habit to put void there since it’s good to do it elsewhere. In C you are allowed to recursively call main in which case such differences may even matter.

    Sadly, only a few compilers support modern C, so on many C compilers you may still get warnings for using modern C features.

    Also, you may see programs to declare main to return different things than int. Such programs can do that if they use a freestanding C implementation. Such C implementations do not impose any restrictions on main since they don’t even know or require such a function in the first place. But to have a common and portable interface to the program’s entry point, the C specification requires strictly conforming programs to declare main with return type int, and require hosted C implementations to accept such programs.

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

Sidebar

Related Questions

Background: I'm familiar with C's select() function. I've been using this function for many
Many of the component libraries and toolkits I'm familiar with lack CLI-specific libraries (zend,
I am not sure if many of you are familiar with the box2d physics
Not sure if many people are familiar with Scaffolding Extensions for Ruby, but I've
Not sure if too many of you are familiar with SWFUpload. It's a flash/js/php
I know the title sounds familiar as there are many similar questions, but I'm
I am pretty familiar with ASP.Net MVC, now I want to try some Spring
Many people have asked about Rails hosting on this site, but I'm not familiar
I am (as I'm sure many of you are) pretty familiar with Rails' MVC
Many of you are familiar with Josh Smith. He does a brilliant job of

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.