Passing Parameters to main()

C allows parameters to be passed from the operating system to the program when it starts executing through two parameters; argc and argv[], as follows:

#include <stdio.h>

main(int argc, char *argv[])


    int n;

    for(n = 0; n < argc; n++)

    printf("\nParameter %d equals %s",n,argv[n]);

Parameter argc holds the number of parameters passed to the program, and the array argv[] holds the addresses of each parameter passed.
argv[0] is always the program name.
There is also a third parameter you can pass to main(): envp. This is a pointer to a list of environment variables that we want the program to be aware of. More on this here.