Everything You Need To Know About Basic Structure of a C Programme

Everything You Need To Know About Basic Structure of a C Programme

Edited By Team Careers360 | Updated on Apr 07, 2022 02:31 PM IST

We'll learn about the basic structure of a C programme in this post. A C programme is broken down into sections. A simple C programme is divided into six sections.

The six portions are as follows:

  • Documentation

  • Link

  • Definition

  • Global Declarations

  • Main functions

  • Subprograms

So, now that we've gotten that out of the way, let's get down to business. This outline is followed throughout the code. Each code follows a similar structure. Let's take a closer look at each of these layers.

Moving on to the next section of this tutorial on the basic structure of a C programme,

Documentation Section

The documentation area of the programme is where the programmer provides information about the programme. He normally offers the program's name, author information, and other facts such as coding time and description. It provides a high-level overview of the code to anyone reading it.

Example

/**

* File Name: Helloworld.c

* Author: Manthan Naik

* date: 09/08/2019

* description: a program to display hello world

* no input needed

*/

Moving on to the next section of this tutorial on the basic structure of a C programme,

Link Section

This section of the code is used to define all of the header files that the application will utilise. The compiler is then instructed to link the header files to the system libraries.

Example

1

#include<stdio.h>

Moving on to the next bit of this basic structure of a C program article,

Definition Section

In this section, we define different constants. The keyword define is used in this part.

1

#define PI=3.14

Moving on to the next section of this tutorial on the basic structure of a C programme,

Global Declaration Section

The declaration of global variables takes place in this section of the code. This section declares all of the global variables that are used. In this section of the code, the user-defined functions are also declared.

1

2

float area(float r);

int a=7;

Moving on to the next section of this tutorial on the basic structure of a C programme,

Main Function Section

The main function is required in all C applications. There are two parts to each main function. There are two parts to this: a declaration part and an execution part. All of the variables are declared in the declaration section. The curly brackets are used to start the execution and the curly close bracket is used to stop it. The curly brackets contain both the declaration and execution parts.

1

2

3

4

5

6

int main(void)

{

int a=10;

printf(" %d", a);

return 0;

}

Moving on to the next bit of this basic structure of a C program article,

Sub Program Section

All the user-defined functions are defined in this section of the program.

1

2

3

4

int add(int a, int b)

{

return a+b;

}

Sample Program

The C program here will find the area of a circle using a user-defined function and a global variable pi holding the value of pi

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

* File Name: areaofcircle.c

* Author: Manthan Naik

* date: 09/08/2019

* description: a program to calculate area of circle

*user enters the radius

**/

#include<stdio.h>//link section

#define pi 3.14;//defination section

float area(float r);//global declaration

int main()//main function

{

float r;

printf(" Enter the radius:n");

scanf("%f",&r);

printf("the area is: %f",area(r));

return 0;

}

float area(float r)

{

return pi * r * r;//sub program

}

Output

https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2019/08/image2-e1565597179647-300x219.png

Articles

Upcoming Exams

Get answers from students and experts
Back to top