You are on page 1of 3

So, What is C Language?

The C Programming Language: C is a general-purpose programming language that was


developed in the 1970s by Dennis Ritchie at Bell Laboratories. It is a structured, imperative
language that is well-suited for low-level programming and system programming tasks. C is
a relatively simple language that is easy to learn, and its syntax is similar to other languages
such as Java, C#, and C++. C is often used to create operating systems, embedded
systems, database systems, and compilers. It is also used extensively in the development of
software for a variety of applications, including word processors, spreadsheets, databases,
and graphics.

Main sections of a C Program:

A C program is divided into six sections:

1. Documentation,
2. Link,
3. Definition,
4. Global Declaration,
5. Main() Function and
6. Subprograms.

While the main section is compulsory, the rest are optional in the structure of the C
program.

Introduction to Structure of the C Program


The structure of a C program is an important concept to understand before writing a
program. The structure of a C program consists of a series of sections, each section having
its own purpose and role. The structure of a C program typically consists of a preprocessor
directive, a main function and other functions, and a program termination section.

The preprocessor directive is used to include any necessary header files and is used to
specify any constants that will be used in the program.

The main function is the main entry point of the program and it is responsible for calling
other functions.

Other functions are used to perform specific tasks within the program and they are usually
called from the main function.

The program termination section is used to clean up and release any resources used by
the program.

By understanding the structure of a C program, you can write more efficient and robust
programs. It is important to understand the structure of a C program before writing any code.
Basic Structure of the C Program

Section Description
Consists of the description of the program such as programmer's name, and
creation date. These are generally written in the form of comments.
e.g.: /*description section*/
Documentation or
//description line 1
//description line 2
All header files are included in this section which contains different functions
from the libraries. A copy of these header files is inserted into your code before
Link compilation.
e.g.: #include<stdio.h>; #include<stdlib.h> etc.
Includes pre-processor directive, which contains symbolic constants.
Definition e.g.: #define allows us to use constants in our code. It replaces all the constants
with its value in the code.
Global Includes declaration of global variables, function declarations, static global
Declaration variables, and functions.
For every C program, the execution starts from the main() function. It is
Main() Function mandatory to include a main() function in every C program.
Includes all user-defined functions (functions the user provides). They can
Subprograms contain the inbuilt functions and the function definitions declared in the Global
Declaration section. These are called in the main() function.

Example: Write a program to calculate your age.


In the following example, we'll calculate age concerning a year.

Algorithm

You've to subtract the current year from your birth year and get your age.

Let's implement this and check:

Code:
/** //Documentation
* file: age.c
* author: you
* description: program to find our age.
*/

#include <stdio.h> //Link


#include <conio.h> //Link
#define YEAR_OF_BIRTH 2000 //Definition
int age(int current); //Global Declaration

int main(void) //Main() Function


{
int current = 2023;
printf("Your Age is: %d", age(current));
return 0;
getch();
}

int age(int current) { //Subprograms


return current - YEAR_OF_BIRTH;
}

OUTPUT: Your Age is: 23

Different sections of the above code


Documentation: In C programmes, single line comments can be written by using double
front slashes i.e. //. We can also write a block of comments or multi-line comments using /* */

Link: All header files are included in this section. A header file consists of C declarations. It
helps the programmer to use pre-defined functions that are already included in the C
compiler or it can be used to include any user made program to use the program’s functions
in the present program.

Definition: This section includes pre-processor directives, which contain symbolic constants
that can be used in the main() function or any sub-function of the program code.

Global Declaration: This section includes all global variables, function declarations, and
static variables. The variables declared in this section can be used anywhere in the program.
They're accessible to all the functions of the program. Hence, they are called global
variables.

Main() Function: In the structure of any C program, this section contains the main function
of the program code. The compiler starts executing from this main() function. The main()
function can use global variables, static variables, inbuilt functions, and user-defined
functions. The return type of the main() function can be void also.

Subprograms: This section consists of user defined functions that can be called from the
main() function. Whenever an user defined function is encountered in the main() function,
the control of the program get shifted to the sub-program and when a return statement is
fetched, the control re-returns to the main() function.

You might also like