0% found this document useful (0 votes)
2 views

Programing With C & C++ _removed (1)

The document outlines the basic structure of a C program, which consists of six main sections: Documentation, Link, Definition, Global Declaration, Main Function, and Sub Program. Each section serves a specific purpose, such as providing program details, linking header files, defining constants, declaring global variables, and executing the main function. A sample program is also provided to illustrate the use of a user-defined function and a global variable.

Uploaded by

nagarajlaxmi756
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programing With C & C++ _removed (1)

The document outlines the basic structure of a C program, which consists of six main sections: Documentation, Link, Definition, Global Declaration, Main Function, and Sub Program. Each section serves a specific purpose, such as providing program details, linking header files, defining constants, declaring global variables, and executing the main function. A sample program is also provided to illustrate the use of a user-defined function and a global variable.

Uploaded by

nagarajlaxmi756
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

2nd Sem Programing with C & C++

Basic Structure of C Programme


A C program is divided into different sections.

There are six main sections to a basic c program.

The six sections are,

Figure: Basic Structure Of C Program

1. Documentation Section
.

➢ The documentation section is the part of the program where the


programmer gives the details associated with the program.

➢ He usually gives the name of the program, the details of the author
and other details like the time of coding and description.

➢ It gives anyone reading the code the overview of the code.

Example

/**

* File Name: Helloworld.c

* Author: Manthan Naik

* date: 09/08/2019

* description: a program to display hello world

Anukali Laxman.
^^^^^^^^^^^^^^
2nd Sem Programing with C & C++

* no input needed

*/

2. Link Section

➢ This part of the code is used to declare all the header files that will
be used in the program.

➢ This leads to the compiler being told to link the header files to the
system libraries.

Example

3. Definition Section

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


in this part.

4. Global Declaration Section

This part of the code is the part where the global variables are declared.
All the global variable used are declared in this part. The user-defined
functions are also declared in this part of the code.

Anukali Laxman.
^^^^^^^^^^^^^^
2nd Sem Programing with C & C++

5. Main Function Section

➢ Every C-programs needs to have the main function.

➢ Each main function contains 2 parts.

➢ A declaration part and an Execution part.

➢ The declaration part is the part where all the variables are declared.

➢ The execution part begins with the curly brackets and ends with the
curly close bracket.

➢ Both the declaration and execution part are inside the curly braces.

6. Sub Program Section


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

Anukali Laxman.
^^^^^^^^^^^^^^
2nd Sem Programing with C & C++

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

Anukali Laxman.
^^^^^^^^^^^^^^
2nd Sem Programing with C & C++

Output

Anukali Laxman.
^^^^^^^^^^^^^^

You might also like