KEMBAR78
Introduction To C Programming | PDF | Programming | Computer Program
0% found this document useful (0 votes)
11 views36 pages

Introduction To C Programming

The document provides an introduction to the C programming language, detailing its history, features, and execution process. Developed by Dennis Ritchie in 1972, C is a general-purpose programming language used for system and application software, known for its efficiency and portability. It also covers the structure of a C program, types of programming languages, and the roles of compilers, interpreters, assemblers, linkers, and loaders in the execution of C code.

Uploaded by

jayanthv040906
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)
11 views36 pages

Introduction To C Programming

The document provides an introduction to the C programming language, detailing its history, features, and execution process. Developed by Dennis Ritchie in 1972, C is a general-purpose programming language used for system and application software, known for its efficiency and portability. It also covers the structure of a C program, types of programming languages, and the roles of compilers, interpreters, assemblers, linkers, and loaders in the execution of C code.

Uploaded by

jayanthv040906
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
You are on page 1/ 36

INTRODUCTION TO C

PROGRAMMING LANGUAGE

National Institute of Technology


Karnataka(NITK)
Department of Computer Science and
Engineering
History of C
● C evolved from two previous languages, BCPL (Basic Combined
Programming Language - for writing s/m s/w) and B.
● Used to develop UNIX
● Used to write modern operating systems
● The C language developed from B by Dennis Ritchie at Bell
Laboratories in 1972 - Exclusively used in Bell Laboratory
Introduction to c language
● C programming language was developed in 1972 by Dennis
Ritchie at bell laboratories of AT&T (American Telephone &
Telegraph), located in U.S.A.
● Dennis Ritchie is known as the founder of c language.
● In 1983, the American National Standards Institute (ANSI)
established a committee to provide a modern, comprehensive
definition of C.
● The resulting definition, the ANSI standard, or "ANSI C", was
completed late 1988.
Types of Programming Languages
What is a programming language
● A natural language is designed to communicate between human.
● A programming language is designed to communicate between
human and computers.
● A programming language is a set of commands, instructions, and
other syntax use to create a software program.
Types of Programming
Languages
● Low-level languages - Computer understands this
● Interact directly with the computer processor or CPU, are capable
of performing very basic commands, and are generally hard to
read.
● Machine code, example of a low-level language, uses code that
consists of just two numbers — 0 and 1.
Types of Programming Languages
● Assembly language, middle-level language, uses keywords to
perform basic commands like read, move and store data.
● High-level languages use natural language - easier for people to
read & write
● Once code is written in a high-level language, an interpreter or
compiler translates this high-level language into low-level code a
computer can understand.
Compiler
● Computer understands only machine language and needs a
translator
● A Compiler translates the program from high level language to
machine language
● Compiler converts the entire program to machine language
● This converted program is stored in memory and executed when
needed.
● Programming Languages like C compilers.
● Generates an intermediate object code.
Compiler
Interpreter
• Interpreter converts high level language one line at a time to
machine language and then executes it.
• Then next line is converted and so on.
• Presence of interpreter is a must while running a program
• Programming Languages like python and ruby uses interpreters
• No object code is generated
• Debugging is easier
Assembler

● An assembler translates assembly language programs into


machine code.
● The output of a assembler is called an object file, which contains a
combination of machine instruction as well as the data required to
place these instructions in memory.
Linker
● Linker is a computer program that links and merges various object
files together in order to make an executable file.
● All these files might have been compiled by separate assembler.
● The major task of a linker is to search and locate referenced
module/routines in a program and to determine the memory
location where these codes will be loaded making the program
instruction to have absolute reference.
Loader

● Loader is a part of operating system and is responsible for loading


executable files into memory and execute them.
● It calculates the size of a program (instructions and data) and create
memory space for it. It initializes various registers to initiate
execution.
Execution flow(The process how C code is
executed inside Computer)

C program (source code) is sent to preprocessor first. The preprocessor


is responsible to convert preprocessor directives into their respective
values. The preprocessor generates an expanded source code.

Expanded source code is sent to compiler which compiles the code and
converts it into assembly code.
Execution flow(The process how C code is
executed inside Computer)

The assembly code is sent to assembler which assembles the code


and converts it into object code. Now a filename.obj file is generated.

The object code is sent to linker which links it to the library such as
header files. Then it is converted into executable code. A filename.exe
file is generated.

The executable code is sent to loader which loads it into memory and
then it is executed. After execution, output is sent to console.
Execution flow diagram
Execution process
Detailed explanation of Execution process
Compiler Interpreter

Takes Entire program as input at Takes Single instruction as input


a time. at a time.
Intermediate Object code is No Intermediate Object code is
generated generated
More memory is required. Less memory is required.

Display error after entire program Display error after each


is checked instruction interpreted (if any)
Uses of C
● C is used to produces code that runs nearly as fast as code written
in assembly language
● Some examples of the use of C might be:
Operating Systems
Compilers
Features of C
• General Purpose Programming Language - Used for writing both
system software and application software
• Robust - Rich set of built in functions and operators to write any
complex program-variety of data types and operators
• Portable - Program for one computer can be run on another with
little or no modification
Features of C

• Structured Programming Language - Problem broken down to


blocks or modules making debugging,testing and maintenance
easier.

• Extensible - We can add our own functions to c library


Features of C language
Applications Of C
● Combines benefits of both low - machine level languages &
high-level developer friendly languages

Operating Systems:
● Scripting of UNIX operating system was the primary purpose
behind creation of C.
● Unix-Kernel, Microsoft Windows utilities and operating system
applications, and a large segment of the Android operating system
have all been scripted in C.
Structure of C Program
• Documentation Section :

This section consists of comment lines which include the name of


programmer, the author and other details like time and date of writing
the program.

• Link Section:

The link section consists of the header files of the functions that are
used in the program.
● Definition Section :
All the symbolic constants are written in definition section. Macros
are known as symbolic constants.

● Global Declaration Section:

The global variables that can be used anywhere in the program are
declared in global declaration section. This section also declares the
user defined functions.
main( ) function section
It is necessary have one main() function section in every C program.
main() contains two parts, declaration and executable part.
The declaration part declares all the variables that are used in
executable part. These two parts must be written in between the
opening and closing braces.
Each statement in the declaration and executable part must end with
a semicolon (;).
The execution of program starts at opening braces and ends at
closing braces.
Subprogram Section:

The subprogram section contains all the user defined functions that
are used to perform a specific task.

These user defined functions are called in the main() function.


Structure of a
C Program
Example C program

● #include<stdio.h>
● void main()
● {
● printf("Hello, World!\n");
● }
Executing a C Program

• Creating the program


vi filename.c
• Compiling the program
• Linking the program with functions that are needed cc filename.c
from the C library
• Executing the program
./a.out
USES OF C Language:
Development of New Languages:
● In Python- C is used for building standard libraries
● C++, Perl and PHP have syntax and control structures based upon
C.

Embedded Systems
● These are typically specialized software for the particular hardware
that they run on.
Network Drivers-
● A network driver is a software program that controls a device used
to connect a computer to a network.
● On system level, these drivers need control of every byte of the
memory, which is better provided by C language.

You might also like