0% found this document useful (0 votes)
13 views4 pages

C Language

The C programming language combines low-level and high-level features, making it versatile for system and application programming. Key features include pointers, memory allocation, recursion, and bit manipulation, which facilitate various applications such as operating systems and databases. The structure of a C program includes sections like documentation, preprocessor, definitions, global declarations, the main function, and user-defined functions, each serving a specific purpose to enhance clarity and reduce errors.

Uploaded by

sanubanu122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

C Language

The C programming language combines low-level and high-level features, making it versatile for system and application programming. Key features include pointers, memory allocation, recursion, and bit manipulation, which facilitate various applications such as operating systems and databases. The structure of a C program includes sections like documentation, preprocessor, definitions, global declarations, the main function, and user-defined functions, each serving a specific purpose to enhance clarity and reduce errors.

Uploaded by

sanubanu122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C programming

C language combines the power of a low-level language and a high-level language. The low-level
languages are used for system programming, while the high-level languages are used for application
programming. It is because such languages are flexible and easy to use. Hence, C language is a widely
used computer language.

It supports various operators, constructors, data structures, and loop constructs. The features of C
programming make it possible to use the language for system programming, development of
interpreters, compilers, operating systems, graphics, general utilities, etc. C is also used to write other
applications, such as databases, compilers, word processors, and spreadsheets.

The essential features of a C program are as follows:

Pointers: it allows reference to a memory location by the name assigned to it in a program.

Memory allocation: At the time of definition, memory is assigned to a variable name, allowing
dynamic allocation of the memory. It means that the program itself can request the operating system
to release memory for use at the execution time.

Recursion: When a function calls itself, it is known as recursion.

Bit-manipulation: It refers to the manipulation of data in its lowest form. It is also known as bits.
The computer stores the information in binary format (0 and 1).

Let's start with the importance of specifying the structure of a C program.

Importance of structure of a C program


Sometimes, when we begin with a new programming language, we are not aware about the basic
structure of a program. The sections of a program usually get shuffled and the chance of omission of
error rises. The structure of a language gives us a basic idea of the order of the sections in a program.
We get to know when and where to use a particular statement, variable, function, curly braces,
parentheses, etc. It also increases our interest in that programming language.

Thus, the structure helps us analyze the format to write a program for the least errors. It gives better
clarity and the concept of a program.

Here, we will discuss the sections of a C program, some practical examples with explanations,
steps to compile and execute a C program.

Let's start.
Sections of a C program

The sections of a C program are listed below:

1. Documentation section
2. Preprocessor section
3. Definition section
4. Global declaration
5. Main function
6. User defined functions

Let's discuss it in detail.

Documentation section
It includes the statement specified at the beginning of a program, such as a program's name, date,
description, and title. It is represented as:

1. //name of a program

Or

1. /*
2. Overview of the code
3. .
4. */

Both methods work as the document section in a program. It provides an overview of the program.
Anything written inside will be considered a part of the documentation section and will not interfere
with the specified code.

Preprocessor section
The preprocessor section contains all the header files used in a program. It informs the system to link
the header files to the system libraries. It is given by:
1. #include<stdio.h>
2. #include<conio.h>

The #include statement includes the specific file as a part of a function at the time of the compilation.
Thus, the contents of the included file are compiled along with the function being compiled.
The #include<stdio.h> consists of the contents of the standard input output files, which contains the
definition of stdin, stdout, and stderr. Whenever the definitions stdin, stdout, and stderr are used in a
function, the statement #include<stdio.h> need to be used.

There are various header files available for different purposes. For example, # include <math.h>. It
is used for mathematic functions in a program.

Define section
The define section comprises of different constants declared using the define keyword. It is given by:

1. #define a = 2

Global declaration
The global section comprises of all the global declarations in the program. It is given by:
1. float num = 2.54;
2. int a = 5;
3. char ch ='z';
The size of the above global variables is listed as follows:
char = 1 byte
float = 4 bytes
int = 4 bytes
We can also declare user defined functions in the global variable section.
Main function
main() is the first function to be executed by the computer. It is necessary for a code to include the
main(). It is like any other function available in the C library. Parenthesis () are used for passing
parameters (if any) to a function.

The main function is declared as:


1. main()
We can also use int or main with the main (). The void main() specifies that the program will not
return any value. The int main() specifies that the program can return integer type data.
1. int main()
Or
1. void main()

2.
Main function is further categorized into local declarations, statements, and expressions.

Local declarations
The variable that is declared inside a given function or block refers to as local declarations.

1. main()
2. {
3. int i = 2;
4. i++;
5. }

Statements

The statements refers to if, else, while, do, for, etc. used in a program within the main function.

Expressions

An expression is a type of formula where operands are linked with each other by the use of operators.
It is given by:

1. a - b;
2. a +b;

User defined functions


The user defined functions specified the functions specified as per the requirements of the user. For
example, color(), sum(), division(), etc.

You might also like