Example of the main() Function

The following program backward prints the arguments entered on a command line such that the last argument is printed first:

#include <stdio.h>
int main(int argc, char *argv[])
{
  while (--argc > 0)
    printf("%s ", argv[argc]);
}

Invoking this program from a command line with the following:

backward string1 string2

gives the following output:

string2 string1

The arguments argc and argv would contain the following values:

Object Value
argc 3
argv[0] pointer to string "backward"
argv[1] pointer to string "string1"
argv[2] pointer to string "string2"
argv[3] NULL


Functions
Function Calls


main() Function
Function Declarations
Function Definitions
Examples of Function Declarations
Examples of Function Definitions