History of C language
CLASS - 2
What is C?
C is a computer programming language used to design computer software and applications.
OR
C is a general-purpose, imperative computer programming language, supporting structured
programming, lexical variable scope and recursion, while a static type system prevents many
unintended operations.
History of C Language
• C is a general-purpose programming language developed at AT & T Bell laboratories of USA
in 1972.
• It was designed by Dennis Ritchie.
• The earlier version of “C” was written by Ken Thompson who adopted it from BCPL (Basic
Combined Programming Language) called “B”.
• Dennis Ritchie studied it, improved and named as “C”.
• Much later, American National Standards Institute(ANSI) Published the “C” language as a
standard, The ANSI C standard was approved in 1989 and was updated in 1999.
• C language was developed to be used in UNIX operating system.
• C is often called a “Middle level language” since it stands in between High level and low
level languages.
Importance of C language
• C has a rich set of built-in functions and operators and these can be used to write any complex programs.
• The c compiler combines the capabilities of an assembly language with the features of a highlevel language and therefore it is well suited for writing both system software and business packages.
• Program written in C are efficient due to several variety of data types and powerful operators.
• There are only 32 keywords; several standard functions are available which can be used for
developing program.
• C is portable language; this means that C programs written for one computer system can be
run on another system, with little or no modification.
• C language is well suited for structured programming, this requires user to think of a problems
in terms of function or modules or block. A collection of these modules make a program
debugging and testing easier
• C language has its ability to extend itself. A c program is basically a collection of functions
that are supported by the C library. We can continuously add our own functions to the library
with the availability of the large number of functions.
C Language Uses
• C is used for writing Operating systems.
• It is used in language translators (compilers, Interpreters and Assemblers).
• It is used in Editors.
• It is used in Worksheets.
• Database Management systems.
Features of C language
• It is a structured language.
• It is a middle-level language.
• C is a portable language.
• C has rich set of operators and built-in functions.
• Fast execution of program when compared to other languages.
• Recursive function calls are possible in c
• Dynamic storage allocation is possible.
• It has the ability to deal efficiently with bits, bytes, addresses, etc..
Computer Languages
To communicate with the computers, we need some languages. These are computer languages.
Computers are machines. A computer can only do what a programmer asks it to do. To perform a particular
task the programmer writes a sequence of instructions called the program. Computers do not understand
natural languages; therefore, to give instructions to computers, different languages have been developed.
These languages are computer languages. Computer languages can be classified into two major categories.
1. Low level languages
2. High level languages.
Low level language
A low-level language is a type of programming language that contains basic instructions
recognized by a computer. Low-level code is often cryptic and not human-readable. Two common
types of low-level programming languages are assembly language and machine language.
Machine Language
The only language which the computer itself can understand is the machine language.
We can use different languages to program a computer, it is translated to machine language before
running that program.
A machine language is the set of instructions which are coded as a series of 1s and 0s. These 1s
and 0s are directly understood by the computer without the help of a translating program. A program written in the form of 0s and 1s is called a machine language program. Each type of computer has its
own machine language. That is, the machine language is machine dependent and the machine
language is different from one type of computer to another.
Assembly Language
The assembly language closely resembles machine language and both are considered as low-level
languages. Assemble language is uses certain pre-defined symbolic codes instead of binary codes.
These symbolic codes are called mnemonics. It can also use symbolic addresses for addressing
memory. Machine level language uses only the binary language. But on the other hand, assembly
language uses mnemonics or symbolic instructions in place of a sequence of 0s and 1s. As example,
we can consider that, to add register A and B in a particular computer, assembly language uses the
mnemonic ‘ADD B’ in place of 10001111. In assembly language, we use symbolic names to denote
addresses and data.Thus writing a program in assembly language has advantages over writing the
same in a machine language.
High- Level Languages
To overcome the difficulties associated with assembly languages, high-level languages were
developed. The instructions written in high-level languages are called statements. The statements
resemble more closely English words and mathematics as compared to mnemonics in assembly
languages. Examples of high-level languages are BASIC, FORTRA, PASCAL, COBOL, PL/1,
PROLOG, C, C++ and etc.
Differences between Machine Language and High Level Language Machine Language
• It is a low level language containing binary digits 0 and 1.
• There is no need to translate it, since it is the only language which the computer itself can
understand.
• It is machine dependent and varies from computer to computer.
• It is very difficult to write a program in a machine language.
• Not closer to any natural languages.
• Relatively less efficient.
• Different to modify or understand
• Debugging is difficult.
High Level Language
• It is a programming language containing meaningful words.
• Compiler or interpreter is used to translate the high-level language into machine language.
• It is machine independent and can be used in different types of computers.
• It is easy to write a program in a highlevel language.
• It is closer to natural language.
• More efficient
• Easy to learn and understand.
• Easy to debug
Source Programs
Programs written in a high level language or low level language are called source programs.
Object Programs
The source programs after getting translated into machine language are known as object programs.
Language Translators
1. Translators
A Computer understands only machine language. To run the programs written in other languages, we
need to convert them into the machine language. Such translation is done by system software
programs called translators.
2. Assembler
A program which translates an assembly language program into a machine language
program is called an assembler. The assembler reads all instructions written using mnemonics into
binary codes and symbolic memory addressing into equivalent binary addresses. Because each CPU
has its own machine language, you require different assemblers for different cpus.
3. Compilers
It is a translator which takes input i.e., High-Level Language, and produces an output of
low-level language i.e. machine or assembly language.
• A compiler is more intelligent than an assembler it checks all kinds of limits, ranges, errors,
etc.
• But its program run time is more and occupies a larger part of memory. It has slow speed
because a compiler goes through the entire program and then translates the entire program
into machine codes.
• The original high-level language program is called the source program. The compiled program i.e.,
the machine language program generated by the compiler after translation is called the object
program
Interpreters
An interpreter is a program which translates one statement of a high-level language program into
machine codes and executes it. In this way it proceeds further till all the statements of the program are
translated and executed.
• It reads the first instruction written in the program and converts that into equivalent machine
language instructions. The the CPU executes those machine language instructions.
• The interpreter reads and translates the next instructions, and so on.
Difference between Compiler and Interpreters
Compiler
• Compiler scans the whole program in one go.
• As it scans the code in one go, the errors(if any) are shown at the end together.
• Main advantage of compilers is its execution time.
• It converts the source code into object code.
• It does not require source code for later execution.
• C, C++, C# etc.
Interpreters
• Translates program one statement at a time.
• Considering it scans code one line at a time, errors are shown line by line.
• Due to interpreters being slow in executing the object code, it is preferred less.
• It does not convert source code into object code instead it scans it line by line.
• It requires source code for later execution.
• Python, Ruby, Perl, SNOBOL, MATLAB, etc.
Structure of C language
1) Comment line
2) Preprocessor directive
3) Global variable declaration
4) Main function ( )
{
Local variables;
Statements;
}
User defined function
}
}
Comment line
It indicates the purpose of the program. It is represented as
/*……………………………..*/
Comment line is used for increasing the readability of the program. It is useful in explaining the
program and generally used for documentation. It is enclosed within the decimeters. Comment line
can be single or multiple line but should not be nested. It can be anywhere in the program except
inside string constant & character constant.
Preprocessor Directive:
#include tells the compiler to include information about the standard input/output library. It is also
used in symbolic constant such as #define PI 3.14(value). The stdio.h (standard input output header
file) contains definition &declaration of system defined function such as printf( ), scanf( ), pow( ) etc.
Generally printf() function used to display and scanf() function used to read value.
Global Declaration:
This is the section where variable are declared globally so that it can be access by all the functions used in the
program. And it is generally declared outside the function.
main()
It is the user defined function and every function has one main() function from where actually program is
started and it is encloses within the pair of curly braces.
The main ( ) function can be anywhere in the program but in general practice it is placed in the first position.
Syntax:
Main()
{
………
………
………
}
The main( ) function return value when it declared by data type as
int main( )
{
return 0
}
The main function does not return any value when void (means null/empty) as
void main(void ) or void main()
{
printf (“C language”);
}
Output: C language
programming style of C language
/*First c program with return statement*/
#include
Steps involved in executing the C program
Type the program and edit it in standard ‘C’ editor and save the program with .c as an
extension. This is the source program .The file should be saved as '*.c' extension only.
2. Compiling (Alt + F9) the Program:
• This is the process of converting the high level language program to Machine level Language (Equivalent
machine instruction).
• Errors will be reported if there is any, after the compilation
• Otherwise the program will be converted into an object file (.obj file) as a result of the compilation
• After error correction the program has to be compiled again
3. Linking a program to library: The object code of a program is linked with libraries that are needed for
execution of a program. The linker is used to link the program with libraries. It creates a file with '*.exe'
extension.
4. Execution of program: This is the process of running (Ctrl + F9) and testing the program with sample data.
If there are any run time errors, then they will be reported.





0 Comments