Basic structure of a C Program

- 1. Comments
Format: /*....*/ or //
Programmers use comments to document programs and improve readability. Comments are optional, nonexecutable statements that are placed in the program to explain what the program does and how the code works.
It is meant to help you and other programmers (who may have to modify or use your code) understand what the program is doing or provides other information.
- 2. The #include Directive
Format: #include<filename>
The purpose is to merge a file with the source program. The #include pre-processing directive tells the pre-processor to replace the directive with a copy of the file specified by the filename argument enclosed within angle brackets <>.
The preprocessor is a utility program that performs various modifications to the source program. A preprocessing directive instructs the preprocessor to modify the source before the compiler executes the program.
- 3. The main() Function
Format:
Void main()
{ Statement;
Statement;
}
All C program begins with the main() function that signals the start of the program. The opening and closing parenthesis ( ) indicate that the identifier is a function. The opening and closing braces { } define the body of the function. Normally, the body consists of a sequence of statements that tell the computer what to do.
- 4. Data Type
Data type stipulates how (in what format) the data is stored and identify:
- how it can saved (or declared)
- what operations can be performed
- how the operation executes
Data types are separated into 2 parts:
1. Built-in data types
2. User-defined data types
There are five basic data types in C; character, integer, floating, point, doubleand char.
- 5. C Statement
A statement is a complete instruction to the computer. Each of the statement is terminated by semicolon (;).
The printf() is an output function from the stdio.h library that you include at the beginning of the program.
- 6. Function Body
The following example shows the body of the main() function in our C program.


