Linux C Command-line Arguments: argc & argv

When main is called in Linux C, it is called with two arguments:
1. argc(argument count): the number of arguments
2. argv(argument vector): a pointer to an array of character strings

Here is a linux shell command “echo”

The output will be:

argc: 3
argv[0]: echo
argv[1]: Rock,
argv[2]: Roll
argv[argc]: 0

Here is a C example to see more clearly about argc and argv:

Then Test the codes:


Leave a Reply

Your email address will not be published. Required fields are marked *