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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:19:14+00:00 2026-05-29T04:19:14+00:00

Possible Duplicate: Why is the type of the main function in C and c++

  • 0

Possible Duplicate:
Why is the type of the main function in C and c++ left to the user to define?

I’ve come across many C’s main function style and syntax of writing but I’m not actually getting what this syntax mean can anybody give brief on each syntax?
why void? why int? why void,int as parameter?

void main() {

}

int main() {

}

int main(void) {

}

void main(void) {

}

int main(int) {

}

int main(int argc, char* argv[]) {

}
  • 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-29T04:19:16+00:00Added an answer on May 29, 2026 at 4:19 am

    There are two forms of conforming implementations specified by the c standard:

    • Hosted Implementation &
    • Freestanding Implementation

    There are based on two types of envrionments that the c standard defines as:

    • Hosted environment &
    • Freestanding environment respectively.

    What is freestanding Environment & What is Hosted Environment?

    A freestanding implementation is one that is designed for programs that are executed without the benefit of an operating system.
    For Ex: An OS kernel or Embedded environment would be a freestanding environment.

    A program using the facilities of an operating system would normally be in a hosted implementation.

    How does a c program execute in these two environments? What is the difference?

    How a C program begins execution in both these environment differs.
    For an Freestanding environment, the program startup can happen by any implementation defined function. There is no requirement that even a main() should exist.

    So any of the functions definitions mentioned in the question can be valid depending upon implementation for that Freestanding Environment. And their function parameters and return values will have implementation defined meaning, So you will need to check their documentation to know their precise meanings.

    Reference:

    5.1.2.1 Freestanding environment

    In a freestanding environment (in which C program execution may take place without any
    benefit of an operating system), the name and type of the function called at program
    startup are implementation-defined
    . Any library facilities available to a freestanding
    program, other than the minimal set required by clause 4, are implementation-defined.

    For an Hosted environment the standard mandates the program execution begins by execution of a main() function and it also mandates how this function will be defined.

    The specifications for the same are given in:

    C99 Standard: 5.1.2.2 Hosted environment

    5.1.2.2.1 Program startup

    1 The function called at program startup is named main. The implementation declares no
    prototype for this function. It shall be defined with a return type of int and with no
    parameters:

       int main(void) { /* ... */ }
    

    or with two parameters (referred to here as argc and argv, though any names may be
    used, as they are local to the function in which they are declared):

       int main(int argc, char *argv[]) { /* ... */ }
    

    or equivalent; or in some other implementation-defined manner.

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

Sidebar

Related Questions

Possible Duplicate: trailing return type using decltype with a variadic template function I'm getting
Possible Duplicate: trailing return type using decltype with a variadic template function I want
Possible Duplicate: return type in c++ #include<iostream> int& fun(); int main() { int p=fun();
Possible Duplicate: Determine if Type is a pointer in a template function I am
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
Possible Duplicate: What does a type followed by _t (underscore-t) represent? While typing in
Possible Duplicate: Default value of a type In C#, to get the default value
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: How do I enumerate an enum? Say I have an enum type
Possible Duplicate: Possible for C++ template to check for a function’s existence? I am

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.