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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:57:45+00:00 2026-06-05T20:57:45+00:00

While reading the K&R 2nd edition I noticed that the programs always began with

  • 0

While reading the K&R 2nd edition I noticed that the programs always began with
“main(){“. I had always thought that main() had to have int or void before it. So that it would look like “int main()” or “void main()”. What is just “main()” and what is the difference?

  • 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-06-05T20:57:47+00:00Added an answer on June 5, 2026 at 8:57 pm

    main() is the old K&R style where the int was omitted as the return type defaults to int if not specified (you should specify it). Additionally, empty parentheses is in K&R style to show it takes no arguments.. in C99 this should now be void to indicate such. Empty parentheses means that the function will accept any number of arguments of any type, which is clearly not what you want. So the final result is:

    int main(void) { ... }
    

    main() should return int.. convention says a return 0; statement at the end will help indicate to the caller that the program executed successfully – non-0 return values indicate abnormal termination.

    A more direct answer to your question would be that main() { ... } works because it’s not wrong. The compiler sees that no return type was declared for the main function so it defaults to int. The empty parentheses indicates to it that main takes any number of arguments of any type, which is not wrong either. However, to conform to C99 style/standard, use

    int main(void) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While reading cocoa tutorials i've noticed that some of the tutorials use AppDelegate and
I have a networkstream (using C#/VB.NET). while on reading values coming like this: &%
I have two simple programs that use named pipes, here is the first: int
While processing multiple gigabyte files I noticed something odd: it seems that reading from
While reading about exception, I will always come across checked exceptions and unchecked exceptions,
I've encoutered these to instructions IN & OUT while reading Understanding Linux Kernel book.
I am not a C programmer. I have just started reading K&R's TCPL last
While reading tutorials regarding pointers, i faced a code like this const int *p;
Mostly i have used $_SESSION , But while reading about Session i got few
Hi friends hope all r doing well. I have a problem while reading xml

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.