1_Structure of C Program
1_Structure of C Program
• Thus, the structure helps us analyse the format to write a program for the
least errors. It gives better clarity and the concept of a program.
• The basic structure of a C
program is divided into 6 parts
which makes it easy to read,
modify, document, and
understand in a particular
format.
• C program must follow the
mentioned outline in order to
successfully compile and
execute.
• Debugging is easier in a well-
structured C program.
Sections of the C Program
1. Documentation
2. Pre-processor / linking
3. Definition
4. Global Declaration
5. Main() Function
6. Sub Programs
1-Documentation
• Good documentation can make your code easier to understand, maintain, and debug and can also
make it more accessible to other developers who may need to use or modify your code in the
future.
• Documentation section consists of the description of the program, the name of the program, and
the creation date and time of the program. It is specified at the start of the program in the form of
comments. Documentation can be represented as:
• /*
description, name of the program, programmer name, date, time etc.
• */
• Anything written as comments will be treated as documentation of the program and this will not
interfere with the given code. Basically, it gives an overview to the reader of the program.
2-linking
• Linking refers to adding necessary header files that are useful in your
code. Header files in C are files that contain function prototypes, data
type definitions, macros, and other declarations that are needed by
other files in a C program.
• They are typically included at the beginning of a source code file
using the #include directive, which tells the pre-processor to insert the
contents of the specified header file into the source code.
• Header files help us to access other’s improved code into our code. A
copy of these multiple files is inserted into our program before the
process of compilation.
3- Definition
• Variables and functions which are declared in this scope can be used
anywhere in the program.
5-Main() function
• In C programming, the main() function is a special function that serves as the entry point for the program.
When a C program is executed, the operating system loads the program into memory and starts executing
instructions from the beginning of the main() function.
• int main() {
• Any code that you want to execute when the program starts should be placed within the main() function.
6-Subprograms
• In C programming, subprograms refer to functions or procedures that
perform a specific task or set of tasks and can be called from other parts of
the program.