Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>§3.6.1/2 (C++03) says </p> <blockquote> <p>An implementation shall not predefine the <code>main</code> function. <strong>This function shall not be overloaded.</strong> 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:</p> </blockquote> <pre><code> int main() { /* ... */ } int main(int argc, char* argv[]) { /* ... */ } </code></pre> <p>You can use either of them. Both are standard compliant.</p> <p>Also, since <code>char *argv[]</code> is equivalent to <code>char **argv</code>, replacing <code>char *argv[]</code> with <code>char **argv</code> doesn't make any difference.</p> <hr> <blockquote> <p>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).</p> </blockquote> <p>No. Both versions cannot co-exist at the same time. One program can have exactly one <code>main</code> 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 <code>argc</code> and <code>argv</code> accordingly, and based on their value, you've to write the logic and the flow of your program.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload