C - main() Function Entry Point


The next five statements define the function main():

int main(void)                    
  printf("hi from book2s.com!");  
  return 0;                       

A function is a named block of code between braces.

Function carries out some specific set of operations.

Every C program consists of one or more functions and every C program must contain a function called main().

A program always starts execution from the beginning of main() function.

The first line of the definition for the function main() is as follows:

int main(void)             // This identifies the function main()

There is no semicolon at the end of the line.

You end execution of main() and specify the value to be returned in this statement:

return 0;  // This returns control to the operating system

This is a return statement that ends execution of main() and returns the value 0 to the operating system.

You return a zero value from main() to indicate that the program terminated normally.

A nonzero value would indicate an abnormal return.

The main() function can call other functions, which in turn may call further functions, and so on.


// Simple C Program
#include <stdio.h>

int main(void)
  printf("Be careful!!\n");
  return 0;// w w  w.j a  v a 2s  .c  o  m