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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:14:25+00:00 2026-05-23T06:14:25+00:00

Two valid versions of main() exist in C++ : int main() // version 1

  • 0

Two valid versions of main() exist in C++:

int main()  // version 1
int main(int argc, char **argv)  // version 2

But both overloads cannot coexist at the same time. Why not? (Potential use case: while running the program from the terminal, if no arguments are passed the first version is called, otherwise the second version is.)

Does the compiler perform a special check to allow just one version per binary?

  • 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-23T06:14:26+00:00Added an answer on May 23, 2026 at 6:14 am

    §3.6.1/2 (C++03) says

    An implementation shall not predefine
    the main function. This function shall
    not be overloaded.
    It shall have a
    return type of type int, but otherwise
    its type is implementation-defined.
    All implementations shall allow both
    of the following definitions of main:

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

    You can use either of them. Both are standard compliant.

    Also, since char *argv[] is equivalent to char **argv, replacing char *argv[] with char **argv doesn’t make any difference.


    But both the versions cannot co-exist at the same time ! (use case can be like: while running the binary from command prompt, if you pass no argument then 1st version should be called else the 2nd version).

    No. Both versions cannot co-exist at the same time. One program can have exactly one main function. Which one, depends on your choice. If you want to process command-line argument, then you’ve to choose the second version, or else first version is enough. Also note that if you use second version, and don’t pass any command line argument, then there is no harm in it. It will not cause any error. You just have to interpret argc and argv accordingly, and based on their value, you’ve to write the logic and the flow of your program.

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

Sidebar

Related Questions

The standard explicitly states that main has two valid (i.e., guaranteed to work) signatures;
I want to implement two different dictionaries with a predefined set of valid keys.
http://www.example.com?a=1&a=2 has a valid form-urlencoded querystring and has two values ( 1 and 2
Two general questions I'm wondering about both in the case for a given file(.js,
I have two versions of a project. One for Silverlight and one for .NET.
I've given an ad hoc version of my app to some users. Two of
I am trying to render the model in two windows in glut. But it
Do any versions of SQL Server support deferrable constraints (DC)? Since about version 8.0,
are these two versions compatible? I get the following exception when deploying the policy-samples:
I'm trying to make a divide and conquer version of binary search, but one

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.