Monday, January 26, 2009

A Simple C Program

main( )

{
printf("hello, world");
}

A C program consists of one or more functions, which are similar to the functions and subroutines of a Fortran program or the procedures of PL/I, and perhaps some external data definitions. main is such a function, and in fact all C programs must have a main. Execution of the program begins at the first statement of main. main will usually invoke other functions to perform its job, some coming from the same program, and others from libraries.
One method of communicating data between functions is by arguments. The parentheses following the function name surround the argument list; here main is a function of no arguments, indicated by ( ). The {} enclose the statements of the function. Individual statements end with a semicolon but are otherwise free-format.
printf is a library function which will format and print output on the terminal (unless some other destination is specified). In this case it prints
hello, world
A function is invoked by naming it, followed by a list of arguments in parentheses. There is no CALL statement as in Fortran or PL/I.

No comments:

Post a Comment