main function


The main() function is a special function. Every C program requires this function as this is considered the starting point for all C programs.

Various compilers allow you to abuse this function, but if you are going to follow the standatds, it expects to return an integer and receive two parameters. Consider the following example.

  
   #include <stdio.h>
 
   int main(
       int   argc,          /* I. number of arguments. */ 
       char *argv[])        /* I. Arguments as character strings. */
   {
       int i;

       printf("Number of Arguments = %d\n", argc);

       for (i=0; i<argc; i++)
       {
          printf("argument %d is %s\n", i, argv[i]);
       }

       exit(0);
   }      



Examples:

example program.

See Also:

malloc function.


Top Master Index Keywords Functions


Martin Leslie