0% found this document useful (0 votes)
4 views8 pages

C Language Introduction

C is a procedural programming language developed by Dennis Ritchie in 1972, primarily for system programming and to write the UNIX operating system. It features simplicity, portability, and supports both low-level and high-level programming, making it widely used for various applications. The structure of a C program includes sections such as documentation, preprocessor, main function, and user-defined functions, which facilitate organized coding and execution.

Uploaded by

swisslinraj86
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
4 views8 pages

C Language Introduction

C is a procedural programming language developed by Dennis Ritchie in 1972, primarily for system programming and to write the UNIX operating system. It features simplicity, portability, and supports both low-level and high-level programming, making it widely used for various applications. The structure of a C program includes sections such as documentation, preprocessor, main function, and user-defined functions, which facilitate organized coding and execution.

Uploaded by

swisslinraj86
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

C Language Introduction

C is a procedural programming language initially developed by Dennis Ritchie in the year 1972 at Bell
Laboratories of AT&T Labs. Dennis Ritchie is known as the founder of the c language.

It was developed to overcome the problems of previous languages such as B, BCPL, etc.

It was mainly developed as a system programming language to write the UNIX operating system. It
inherits many features of previous languages such as B and BCPL.

Features of C Language

C is the widely used language. It provides many features that are given below.

1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. Structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers
9. Recursion
10. Extensible
1) Simple
C is a simple language in the sense that it provides a structured approach (to break
the problem into parts), the rich set of library functions, data types, etc.

2) Machine Independent or Portable


Unlike assembly language, c programs can be executed on different machines with
some machine specific changes. Therefore, C is a machine independent language.

3) Mid-level programming language


Although, C is intended to do low-level programming. It is used to develop system
applications such as kernel, driver, etc. It also supports the features of a high-level
language. That is why it is known as mid-level language.

4) Structured programming language


C is a structured programming language in the sense that we can break the program
into parts using functions. So, it is easy to understand and modify. Functions also
provide code reusability.

5) Rich Library
C provides a lot of inbuilt functions that make the development fast.

6) Memory Management
It supports the feature of dynamic memory allocation. In C language, we can free the
allocated memory at any time by calling the free() function.

7) Speed
The compilation and execution time of C language is fast since there are lesser inbuilt
functions and hence the lesser overhead.
8) Pointer
C provides the feature of pointers. We can directly interact with the memory by using the
pointers. We can use pointers for memory, structures, functions, array, etc.

9) Recursion
In C, we can call the function within the function. It provides code reusability for
every function. Recursion enables us to use the approach of backtracking.

10) Extensible
C language is extensible because it can easily adopt new features.

Structure of a C program
The structure of a C program means the specific structure to start the programming in the C
language. Without a proper structure, it becomes difficult to analyze the problem and the solution. It
also gives us a reference to write more complex programs.

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).

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()

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.

The program (basic or advance) follows the same sections as listed above.

Return function is generally the last section of a code. But, it is not necessary to include. It is used
when we want to return a value. The return function returns a value when the return type other
than the void is specified with the function.

Return type ends the execution of the function. It further returns control to the specified calling
function. It is given by:

1. return;

Or

1. return expression ;

For example,
return 0;

Examples

Let's begin with a simple program in C language.

Example 1: To find the sum of two numbers given by the user

It is given by:

1. /* Sum of two numbers */

2. #include<stdio.h>

3. int main()

4. {

5. int a, b, sum;

6. printf("Enter two numbers to be added ");

7. scanf("%d %d", &a, &b);

8. // calculating sum

9. sum = a + b;

10. printf("%d + %d = %d", a, b, sum);

11. return 0; // return the integer value in the sum

12. }

13. </stdio.h>

Output

The detailed explanation of each part of a code is as follows:

It is the comment section. Any statement described in it is


not considered as a code. It is a part of the description
/* Sum of the two numbers */ section in a code.
The comment line is optional. It can be in a separate line or
part of an executable line.

It is the standard input-output header file. It is a command


#include<stdio.h>
of the preprocessor section.

main() is the first function to be executed in every program.


int main() We have used int with the main() in order to return an
integer value.
{… The curly braces mark the beginning and end of a function. It
} is mandatory in all the functions.

The printf() prints text on the screen. It is a function for


printf() displaying constant or variables data. Here, 'Enter two
numbers to be added' is the parameter passed to it.

It reads data from the standard input stream and writes the
scanf()
result into the specified arguments.

The addition of the specified two numbers will be passed to


sum = a + b
the sum parameter in the output.

A program can also run without a return 0 function. It simply


return 0 states that a program is free from error and can be
successfully exited.

You might also like