argv and argc are how command line arguments are passed to main() in C and C++.

argc will be the number of strings pointed to by argv. This will (in practice) be 1 plus the number of arguments, as virtually all implementations will prepend the name of the program to the array.

The variables are named argc (argument count) and argv (argument vector) by convention, but they can be given any valid identifier: int main(int num_args, char** arg_strings) is equally valid.

They can also be omitted entirely, yielding int main(), if you do not intend to process command line arguments.

Try the following program:

#include <iostream>

int main(int argc, char** argv) {
    std::cout << "Have " << argc << " arguments:\n";
    for (int i = 0; i < argc; ++i) {
        std::cout << argv[i] << "\n";
    }
}

Running it with ./test a1 b2 c3 will output

Have 4 arguments:
./test
a1
b2
c3
Answer from user229044 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › command-line-arguments-in-c-cpp
Command Line Arguments in C - GeeksforGeeks
July 3, 2026 - argc stores the total number of command-line arguments, while argv is an array containing each argument as a string. Arguments are separated by spaces, and values containing spaces should be enclosed in quotation marks.
🌐
Reddit
reddit.com › r/learnprogramming › [c]explain to me the use of argc and argv.
r/learnprogramming on Reddit: [C]Explain to me the use of argc and argv.
October 11, 2014 -

Using argc and Argv as a argument has been a problem for me in my intro to programming class. I could use some eli5 help with it.

Discussions

argc and argv? - C++ Forum
I have came across this program(below) ... with the argc and argv but it didn't really explain it very well, so if you could explain that any better that would be great. Also, the program is supposed to require a password and tell me if it is right or wrong, and it just says ... I tried putting my computer password in the "mypassowrd" ... More on cplusplus.com
🌐 cplusplus.com
What does argc and argv do in C?
They capture information passed by the operating system when your program starts. It’s just a collection of strings representing the command line options passed in and the length More on reddit.com
🌐 r/C_Programming
20
0
October 7, 2024
C#のArgcとArgv? C#で引数の数をどうやって知るの?
309K subscribers in the csharp community. All about the object-oriented programming language C#. More on reddit.com
🌐 r/csharp
O que argc e argv fazem em C?
By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy. ... User Agreement Reddit, Inc. More on reddit.com
🌐 r/C_Programming
20
0
October 7, 2024
People also ask

Is it mandatory to use both argc and argv?
No, you can omit one if not needed, but the order in the main() definition should remain correct.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › argc-argv
argc and argv in C: Explained with Examples
What is the default value of argc?
It’s always at least 1 because the program name is always included.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › argc-argv
argc and argv in C: Explained with Examples
What does argv[0] contain?
It contains the name or path of the program being executed.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › argc-argv
argc and argv in C: Explained with Examples
🌐
University of Toronto
teach.cs.toronto.edu › ~ajr › 209 › notes › argv.html
CSC 209: argc and argv in C
While "argc" and "argv" are theoretically arbitrary parameter names, the use of the names "argc" and "argv" is so standard that you should never use any other name. Since a string can be passed around as a value of type pointer-to-char, argv will be an array of pointers-to-char.
🌐
IBM
ibm.com › docs › en › i › 7.4.0
IBM notice: The page you requested cannot be displayed
If you typed the address, please make sure that the spelling is correct. Note: Most addresses are case sensitive. For information on IBM offerings, start from the IBM homepage. Search the IBM Web site. ... This option lets you send an information request and tell us about a broken link.
Find elsewhere
🌐
Medium
medium.com › @chuxoguh › understanding-command-line-arguments-exploring-argv-and-argc-in-c-programming-language-a198395028c9
Understanding Command-Line Arguments: Exploring argv and argc in C Programming Language | by Chux | Medium
June 12, 2023 - The name "argc" stands for "argument count." This parameter provides valuable information about the number of arguments available for processing within the program. argv is an array of strings (char*) that holds the actual command-line arguments.
🌐
YouTube
youtube.com › watch
Mastering Command Line Arguments in C: argc and argv made easy - YouTube
Curious about how to make your C programs accept input directly from the command line? In this beginner-friendly tutorial, we dive into the basics of using c...
Published: November 6, 2024
🌐
WsCube Tech
wscubetech.com › resources › c-programming › argc-argv
argc and argv in C: Explained with Examples
5 days ago - Learn argc and argv in C programming. Understand command-line arguments, their syntax, uses, practical examples, and how argc and argv work. Read now!
🌐
Dragon Zap
dragonzap.com › blog › understanding-argc-and-argv-in-c-programming-lang
Understanding argc and argv in C Programming: A Comprehensive Guide | Dragon Zap
March 9, 2023 - The value of argc is determined by the operating system and is based on the number of arguments provided by the user. The first argument, argv[0], is always the name of the program itself.
🌐
Skenz
skenz.it › cs › c_language › argc_and_argv
cs:c_language:argc_and_argv [Skenz - How To Wiki]
*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define LEN 50 int main(int argc, char *argv[]) { int i; char s[LEN+1]; int string_length; /* Running the program as follows: prog_name.exe -c 4 sTriNg the variables *argv[] and argc contains the following values: argv[0]="prog_name.exe" argv[1]="-c" argv[2]="4" argv[3]="sTriNg" argc=4 And the output of the program will be STRI */ if(argc==4){ /* If the user has specified the option -c */ string_length = atoi(argv[2]); strncpy(s, argv[3], string_length); s[string_length] = '\0'; }else{ /* If the only argument is <string> */ strcpy(s, argv[1]); string_length = strlen(s); } for(i=0; i<string_length; i++){ s[i] = toupper(s[i]); } printf("The resulting string is: %s\n", s); return 0; }
🌐
Cplusplus
cplusplus.com › forum › beginner › 110792
argc and argv? - C++ Forum
argc and argv are the arguments to the program itself. argc being the number of arguments, and argv being the actual arguments. If you dont understand the concept, think of it as: The same way that a function can but doesnt have to take arguments, your program can also take arguments.
🌐
Old Dominion University
cs.odu.edu › ~zeil › cs333 › f13 › Public › faq › faq-htmlsu7.html
What are argc and argv?
argc is the number of arguments on the command line (including the program name itself) argv is an array of C-style strings (character arrays, with a null character at the end of each string)
🌐
Let's Code
codeitaway.wordpress.com › 2011 › 09 › 20 › lesson-14-accepting-command-line-arguments-in-c-using-argc-and-argv
Lesson 14: Accepting command line arguments in C using argc and argv | Let's Code
September 20, 2011 - The integer, argc is the argument count. It is the number of arguments passed into the program from the command line, including the name of the program. The array of character pointers is the listing of all the arguments. argv[0] is the name ...
🌐
Au
phys.au.dk › ~fedorov › prog › 2025 › notes › cmdline.htm
Command-Line Arguments in POSIX Systems
argc (Argument Count): This integer variable holds the number of command-line arguments, *including* the name of the program itself. So, if you run a program with no arguments other than its name, argc will be 1. argv (Argument Vector): This is an array of C-style strings (char*).
🌐
The C Book
publications.gbdirect.co.uk › c_book › chapter10 › arguments_to_main.html
The C Book — Arguments to main
When a program starts, the arguments to main will have been initialized to meet the following conditions: ... argv[0] through to argv[argc-1] are pointers to strings whose meaning will be determined by the program.
🌐
University of Texas
cs.utexas.edu › ~djimenez › utsa › cs1713-2 › lecture14.html
Command line arguments: argc and argv
The first parameter is an integer, usually called argc, that tells how many command line arguments there are, including the command itself. The command line arguments describe what the Unix command line looked like when the program was executed. The second argument to main, usually called argv, ...
🌐
Quora
quora.com › What-is-the-purpose-of-argc-and-argv-in-the-main-function
What is the purpose of 'argc' and 'argv' in the main function? - Quora
Answer (1 of 5): Let’s start with problem. We have a program which takes some input. Input is simple, could be via well defined file or keyboard. But that’s problematic to automate, eg start program with different parameters from some script in automated manner.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_command_line_arguments.htm
Command Line Arguments in C
It should be noted that argv[0] holds the name of the program itself and argv[1] is a pointer to the first command line argument supplied, and *argv[n] is the last argument. If no arguments are supplied, then argc will be set at "1" and if you ...
🌐
cppreference.com
en.cppreference.com › c › language › main_function
Main function - cppreference.com
... The names argc and argv stand for "argument count" and "argument vector", and are traditionally used, but other names may be chosen for the parameters, as well as different but equivalent declarations of their type: int main(int ac, char** av) is equally valid.