C main Function

Description

In all C programs, the starting point is the main() function. Every C program has one main() function.

Example

The following code has a main function which is the starting point of the program.


#include <stdio.h>
  //ww  w . j  a v a2 s  .c  o m
int main()
{
    printf("Goodbye!\n");
    return(0);
}

The code above generates the following result.

Example 2

main() function can accept parameter from command line. The following code shows how to use main() function to accept the command line argument parameters.


#include <stdio.h>
// ww  w  . j  av  a2 s  .  c  o  m
int main(int argc, char *argv[])
{
  printf("Program name: %s\n", argv[0]);
  int i;
  for(i = 1 ; i<argc ; i++)
    printf("\nArgument %d: %s", i, argv[i]);
  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Language Basics »




C Language Basics
Data Types
Operator
Statement
Array