More on the main() Function

A function body is enclosed between two curly braces. Every function must have a body, although it can be empty. All code in a C program must be contained within a function. The code in the body of one function is separate from that of other functions.

 

Every C program must have at least one function, and at least one function must be named main(). The main() function may call other functions; in fact, the printf() command we have been using is itself a function. After a function finishes executing, control returns to the function that called it. After the main() function finishes executing, control is returned to the operating system.

#include <stdio.h>

int aFunction(void){/*this is the beginning ofthe function*/
  printf("Vote for Governor Santini!");
  /*
   * return control to the calling function
   */
  return 0;
}/*this is the end of the function*/



int main(void){/*this is the beginning ofthe function*/
    
  /*
   * call aFunction()
   */
  aFunction();
 
 
  /*
   * execution returns to the main() function
   */
  printf("Tuesday is Soylent Green Day.");

  /*
   * return control to the
   * OS
   */
  return 0;
 
}/*this is the end of the function*/

 

Note that all executable statements in C must end with a semicolon, this includes function calls.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s