A C program is composed of preprocessor commands, a global declaration section, and one or more functions
STRUCTURE
OF A C PROGRAM
A
C program is composed of preprocessor commands, a global declaration section,
and one or more functions (Figure 2.2).
The
preprocessor directives contain special instructions that indicate how to
prepare the program for compilation. One of the most important and commonly
used preprocessor commands is include which tells the compiler that to execute
the program, some information is needed from the specified header file.

In
this section we will omit the global declaration part and will revisit it in
the chapter on Functions.
A
C program contains one or more functions, where a function is defined as a
group of C statements that are exe- cuted together. The statements in a C
function are written in a logical sequence to perform a specific task. The main
() function is the most important function and is a part of every C program.
The execution of a C program begins at this function.
All
functions (including main()) are divided into two parts the declaration section
and the statement section. The declaration section precedes the statement
section and is used to describe the data that will be used in the function.
Note that data declared within a function are known as local declaration as
that data will be visible only within that function. Stated in other terms, the
life-time of the data will be only till the function ends. The statement
section in a function contains the code that manipulates the data to perform a
specified task.
From
the structure given above we can conclude that a C program can have any number
of functions depending on the tasks that have to be performed, and each
function can have any number of statements arranged according to specific
meaningful sequence.
Note
Programmers
can choose any name for functions. It is not mandatory to write Function1,
Function2, etc., but with an exception that every program must contain one
function that has its name as main().
Programming in C: Unit I (b): Introduction to C : Tag: : - Structure of a C Program
Programming in C
CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation
Professional English II
HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation
Statistics and Numerical Methods
MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation
Engineering Graphics
GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation
Physics for Electrical Engineering
PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation
Basic Civil and Mechanical Engineering
BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation
Electric Circuit Analysis
EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation
Physics for Electronics Engineering
PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation
Electrical and Instrumentation Engineering
BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation
Circuit Analysis
EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation
Materials Science
PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation
Basic Electrical and Electronics Engineering
BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation
Physics for Civil Engineering
PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation
Basic Electrical, Electronics and Instrumentation Engineering
BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation
Physics for Information Science
PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation
Basic Electrical and Electronics Engineering
BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation
Programming in C
CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation