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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:35:16+00:00 2026-05-17T17:35:16+00:00

Possible Duplicates: What are the arguments to main() for? What does int argc, char

  • 0

Possible Duplicates:
What are the arguments to main() for?
What does int argc, char *argv[] mean?

Every program is starting with the main(int argc, char *argv[]) definition.

I don’t understand what it means. I would be very glad if somebody could explain why we use these arguments if we don’t use them in the program? Why not just: int main()?

Is the name of the program one of the elements of *argv[] and argc is the count of the number of arguments in *argv[]? What are the other arguments sent to *argv[]? How do we send them?

  • 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-17T17:35:16+00:00Added an answer on May 17, 2026 at 5:35 pm

    The arguments argc and argv of main is used as a way to send arguments to a program, the possibly most familiar way is to use the good ol’ terminal where a user could type cat file. Here the word cat is a program that takes a file and outputs it to standard output (stdout).

    The program receives the number of arguments in argc and the vector of arguments in argv, in the above the argument count would be two (The program name counts as the first argument) and the argument vector would contain [cat,file,null]. While the last element being a null-pointer.

    Commonly, you would write it like this:

    int  // Specifies that type of variable the function returns.
         // main() must return an integer
    main ( int argc, char **argv ) {
         // code
         return 0; // Indicates that everything went well.
    }
    

    If your program does not require any arguments, it is equally valid to write a main-function in the following fashion:

    int main() {
      // code
      return 0; // Zero indicates success, while any 
      // Non-Zero value indicates a failure/error
    }
    

    In the early versions of the C language, there was no int before main as this was implied. Today, this is considered to be an error.

    On POSIX-compliant systems (and Windows), there exists the possibility to use a third parameter char **envp which contains a vector of the programs environment variables. Further variations of the argument list of the main function exists, but I will not detail it here since it is non-standard.

    Also, the naming of the variables is a convention and has no actual meaning. It is always a good idea to adhere to this so that you do not confuse others, but it would be equally valid to define main as

    int main(int c, char **v, char **e) {
       // code
       return 0;
    }
    

    And for your second question, there are several ways to send arguments to a program. I would recommend you to look at the exec*()family of functions which is POSIX-standard, but it is probably easier to just use system("command arg1 arg2"), but the use of system() is usually frowned upon as it is not guaranteed to work on every system. I have not tested it myself; but if there is no bash,zsh, or other shell installed on a *NIX-system, system() will fail.

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

Sidebar

Related Questions

Possible Duplicate: Why no switch on pointers? int main(int argc, char** argv) { void*
Possible Duplicate: Difference between void main and int main? Alright, so I'm using bloodshed
Possible Duplicates: What does WPF still have to offer over Silverlight 4? Why change
Possible Duplicate: Inspect the names/values of arguments in the definition/execution of a JavaScript function
Possible Duplicate: Windows Program: How to snoop on command line arguments? I am working
Possible Duplicates: Why does this go into an infinite loop? Things like i =
Possible Duplicate: Parse string into argv/argc I'm trying to write a fake shell using
Possible Duplicate: Define a method that has many (or infinite) arguments I have the
Possible Duplicates: Why is lock(this) {...} bad? In C# it is common to use
Possible Duplicate: Multiple arguments to function called by pthread_create()? How to pass more than

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.