C program strucutre

Friday, September 03, 2004

 

C program structure


#include <stdio.h>
void main()
{
printf( "Hello World From Team A \n" );
}

Line 1: #include <stdio.h>.
As part of compilation, the C compiler runs a program called the C preprocesor. The preprocessor is able to add and remove code from your source file. In this case, thedirective #include tells the preprocessor to include code from the file stdio.h. This file contains declarations for functions that the program needs to use. A declaration for the printf function is in this file.

Line 2: void main(). This statement declares the main function. A C program can contain many functions but must always have one main function. A function is a self-contained module of code that can accomplish some task. The "void" specifies the return type of main. In this case, nothing is returned to the operating system.

Line 3: {
This opening bracket denotes the start of the program.

Line 4: printf( "Hello World From Team A \n");
Printf is a function from a standard C library that is used to print strings to the standard output, normally your screen. The compiler links code from these standard libraries to the code you have written to produce the final executable. The
"\n" is a special format modifier that tells the printf to put a line feed at the end of the line. If there were another printf in this program, its string would print on the next line.

Line 5: } This closing bracket denotes the end of the program.


Archives

September 2004  

This page is powered by Blogger. Isn't yours?