A Basic Structure of C Programing Language

Sumant jha
8 min readJan 18, 2021

In the series of learning C Programming Language. Here we are going to talk about the structure of c program. What is the basic structure of c program? How does the program look like? How to write a c program? We will also see this with a simple example. We’ll take a simple example and we’ll write a program here.

So now let us discuss what is the basic structure of c program. What sections are there in a c program? How you can write a c program? What you have to include and see, I am going to discuss all the sections but some sections are optional and some sections are essential to include in your program. It is not necessary that you have to include all the sections in your program when you are writing a program.

Documentation Section

So the very first section is your documentation section or you can say it is the comment section here what you include. Comments mean what information you include in this section like the author of that program who has developed that program date the date and time of development of that program and a brief description of that program.

Like suppose let us take one example, I want to write a program for addition of two numbers so what you can include in this documentation section this you can include author is SK Jha you can include the date as well as time and you can also write down a brief description like a program for addition of two numbers and now these are comments you have to include this line in the comment section.

Like you can say if you write this one-two forward-slash (//) this is a single-line comment in c language or in the structure of c program.

// this is single-line comment

Now, what does this mean this line would be ignored by the compiler. The compiler will not execute this line. The compiler is not going to convert this line into object code. Completely compiler will ignore this line.

And if you want to comment on multiple lines then there is also a multiple line comment. Here you can write a forward-slash asterisk(/*)

/* This is multi
line comment */

These two lines here are trig for comment in c language. And this is the multi comment in the structure of c program.

So whatever comment you want to include you can include either a single-line comment or multiple line comment. So now what is the purpose of including this thing? If the compiler ignores this thing compiler will not execute this thing. It is just for understanding for future use. Like, suppose if anyone wants to use your program in the future and he wants to understand what this program is all about then rather than looking at code c addition of two numbers. It is simply having maybe four or five lines simple as that you can look at that program and you can easily figure out. This program is about the addition of two numbers but actual programs when they develop software then programs are having lots of lines of code so by looking at that code we cannot easily understand what this program is all about. But if you look at this documentation section which is above that program you can easily understand that who has developed this program, the date and the time, and what this program? what this code is all about? just by looking at the documentation section. So this section is just for the understanding and a reading of the program to enhance the reading of the program to understand the program. What the program is all about it is optional. Generally when we write a program? we don’t include this documentation section. But it’s better to include. It should be in your practice, but because in the future when you will write those programs then obviously you have to include the documentation section. So it’s better you start including this section from today. When you write the program but this is completely optional.

Link Section

The second section is the link section here in the structure of c program. We include header files means like we include hash include stdio.h is what?

#include<stdio.h>
#include<conio.h>

It is a preprocessor. Now stdio means the full form is standard input output don’t touch extension why because it is header file now there are some predefined functions in c library. Built-in functions and we use those functions that I have already discussed when we’re discussing the features of C languages. C is having many built-in functions many predefined functions you can directly use those functions. Now, this header file is for what standard input output means for which function for printf and scanf. printf is what for output and scanf is what to take input. Now see these are predefined functions and where these functions are defined? In this library in this header file stdio.h. So if you want to include this in your program then you have to include this header file in your program. Why so because see compiler doesn’t understand what does that mean printf we understand printf is what to give output to print something on screen but the compiler is not having its own brain he’ll not understand what printf means. So you have to provide the meaning the code. And when the compiler will look at that code then the only the compiler is able to understand that printf means. It has to print something and where that definition of this function is where that code about this function is written in this header file, in this library stdio.h

So see same suppose if you want to add two numbers then simply if you write (sum=a+b) sum compiler is not able to understand sum is what? But if you write down the logic the code sum is equal to suppose a variable a plus b. Then the compiler will do sum of two variables a plus b numbers and will add will store that number into in sum variable. Same for printf also you have to define you have to tell the compiler what printf means. So that meaning is in this header file studio.h It’s already defined you don’t have to write down the code in your program for printf function. You can directly use this function but you have to include this header file to tell the compiler the meaning of this thing. Same as scanf the meaning of this thing is also in this header file.

If you include (#include) hash include conio.h conio means console input output. The full form sometimes they can ask in viva this is for what if you use a function getch(). It is basically to hold the screen output screen when we will discuss a complete program then we will discuss what does that means. So the function or this function is already defined in this header file. So when this you will write this in your code compiler will not able to understand it. If you will not include this file. But to tell the compiler the meaning of this getch then why you are including this file. You have to you want to hold the output screen. So that meaning that the code of this function is already written in this library. That is why you are including this new .h

#include<math.h>

Now suppose if you want to use some a math function like square root, sqrt, or power. Those functions are defined in math.h at that time you will include here (#include) hash include math.h If you want to use some string functions like strlen() you want to find out the length of a string strcmp() string compare string concatenation then compiler is not aware about this thing that string length means he has to find out the length of the string. where this definition is written. The code of this function is written the meaning of this function is written in the library string.h So there you will include #include Then the compiler will come to know string length strlen() means. He has to, he will have to find out the length of that string. That is why we include this header file and this is what links section because the linker is going to link this thing. The code the c library code means. The predefined function code into your program. How the linking and loading is done that also will discuss when we will discuss the compilation process so this is what link section in the structure of c program. When you include the header files.

Definition Section

The third section is what definition section in the structure of c program. This section defines all the symbolic constants. Now, what does that mean suppose I want to write in a program I want to use PI you know the PI means 3.14 right so I’m using this PI in a program. Suppose 10 times right so rather than writing 3.14 ten times in a program. What you can do? you can write down here #define 3.14 so if you use this #defined this is what macro definition. So whenever in the program this is written PI suppose 10 times. PI is written in a program so everywhere that will replace, that will be replaced with this value.

#define PI 3.14
#define max 100

Let us suppose one more example I am writing here #define max=100 or mean value max says 100 and max i am using in a program. Suppose 10 times or 15 times so 20 times so rather than writing 10 times 100 100 100 you can write down this thing. One more advantage is what if you want to suppose change value of max suppose i want to change it from 100 to 200. So if you will not write this thing if in a program. You have written that value 100 ten times then at ten places you have to update that value 200 but if you use this thing then in a program. Rather than this value, you can simply write down the name max so when you are going to update then you just have to update here only 100 to 200 that’s it. And that will automatically be replaced by 200 every time you write max in a program. So that is you can say the advantage of using these macro definitions or here you can also write down a small function definition like.

Learn the complete lesson about the structure of c program.

You can also visit our institute

My Computer Institute

Address: Ground Floor, B/22, Topaz Trade Center, Tulinj Rd, opp. Janta Bazar, near Amit Dairy, Nalasopara East, Nala Sopara, Maharashtra 401209

Phone: 084465 30415 / 084465 30416

--

--