Understanding Your First Program

The first line of the program

#include <stdio.h>

tells the compiler information about the printf routine that is used later in the program. The line of the program

int main (void)

informs the system that the name of the function is main, and that it returns an integer value. Main() is a special name that indicates precisely where the program is to begin execution.

All program statements included between the curly braces are taken as part of the main routine by the system. The first statement specifies that a routine named printf is to be called. The parameter or argument to be passed to the printf routine is the string of characters

” This is my first program.\n”

The printf routine is a function in the C library that simply displays its argument. The last two characters in the string, namely the backslash (\) and the letter n, are known collectively as the newline character. A newline character tells the system to do precisely what its name implies—that is, go to a new line.

All program statements in C must be terminated by a semicolon ” ; “. The last statement in main

return 0;

says to finish execution of main, and return to the system a status value of 0. Zero is used by convention to indicate that the program completed successfully, without any errors.

You may also like...