Programming in C
Introduction
By,
Mrs. SHRUTI TAVARAGUNDI
Assistant Professor, Dept. of CSE,
JSSATE, Bengaluru - 60
What is C Language?
C is a general-purpose computer programming
language.
C is also said to be structures programming language
or function oriented programming language.
C is a High level programming language.
Why do we use C?
C language is used to create applications or
software.
Initially, C was developed to create an operating
system called UNIX.
The popular software like Linux OS, PHP & MySQL
are created using C language.
Why do we use C?
Generally C Language is used to create the
following…
• Operating Systems
• Language Compilers
• Assemblers
• Interpreters
• Text Editors
• Network Drivers
• Databases
History of C Language?
C Language was developed by Dennis Ritchie in the
year of 1972.
Dennis
Ritchie
History of C Language?
Let’s see the programming languages that were developed before C
language…
CPL – Common Programming Language invented by
Martin Richards in 1960’s
BCPL – Basic Combined Programming Language by Ken
Martin Richards in 1966 Thompson
B Language – by Ken Thompson & Dennis Ritchie in
1969
Traditional C – by Dennis Ritchie in 1972
K&R C – by Kernighan & Dennis Ritchie in 1978
ANSI C – by ANSI Committee in 1989 Dennis
Ritchie
ANSI/ISO C – by ISO Committee in 1990
C99 – by Standardization Committee in 1999
Software used to create and execute a C Program
Following are the applications and software used to create and execute C
programs.
Turbo C
Turbo C++
GNU C
Code Blocks
Net Beans
Introduction to Computer Systems
What is a Computer?
The Computer is an electronic device which operates under the control
of instructions stored in its memory and it takes the data from the user,
a process that data gives the result and stores the result for future use.
What does a computer consist of?
Every computer mainly consists of three things and those are...
1.Hardware
2.Software
3.User
Here the user interacts with the software, and the software
makes the computer hardware parts to work for the user.
What is Computer Hardware?
The computer hardware is the physical part of a computer.
The computer hardware components are as follows...
1.Input Devices - These are the parts through which a user can give the data to the
computer.
2.Output Devices - These are the physical components of a computer through which the
computer gives the result to the user.
3.Storage Devices - These are the physical components of a computer in which the data
can be stored.
4.Devices Drives - Using drives, user can read and write data on to the storage devices like
CD, floppy, etc.,
5.Cables - Various cables (Wires) are used to make connections in a computer
6.Other Devices - Other than the above hardware components, a computer also contains
components like Motherboard, CPU (Processor), SMPS, Fans, etc.,
Input Devices
Computer input
devices are the
physical components
of the computer which
are used to give the
data given by the user
to the computer. Using
input devices the user
can give the data to the
computer.
Output Devices
Computer output
devices are the
physical components
of the computer
which are used to
give the computer
result to the User.
Using output devices,
the user can see the
computer-generated
result.
Storage Devices
Computer storage
devices are the
physical components
of the computer which
are used to store data
internally or
externally.
Device Drives
Computer Device drives are the physical components of
the computer which are used to read and write data on
the storage devices.
Computer Cables
In a Computer, various
cables are used to
make connections
among the various
hardware components
of the computer.
Other Devices
Other devices of the computer are shown below...
CPU (Processor)
SMPS
Motherboard
CPU Fan (Heat Sink)
How does Computer work?
Computer Languages
When a user wants to give any instruction to the computer the user
needs a specific language and that language is known as a computer
language.
The user interacts with the computer using programs and that
programs are created using computer programming languages like C,
C++, Java, etc., Every computer programming language contains a set
of predefined words and a set of rules (syntax) that are used to create
instructions of a program.
Computer languages are the languages through which the
user can communicate with the computer by writing program
instructions.
Computer Languages Classification
Over the years, computer languages have been evolved from Low-Level to
High-Level Languages. In the earliest days of computers, only Binary
Language was used to write programs. The computer languages are classified as
follows...
Low-Level Language (Machine Language)
Low-Level language is the only language which can be
understood by the computer. Binary Language is an example
of a low-level language.
Low-level language is also known as Machine Language. The
binary language contains only two symbols 1 & 0.
All the instructions of binary language are written in the form
of binary numbers 1's & 0's.
A computer can directly understand the binary language.
Machine language is also known as the Machine Code.
As the CPU directly understands the binary language
instructions, it does not require any translator.
CPU directly starts executing the binary language
instructions and takes very less time to execute the
instructions as it does not require any translation.
Low-level language is considered as the First
Generation Language (1GL).
Advantages
•A computer can easily understand the low-level
language.
•Low-level language instructions are executed directly
without any translation.
•Low-level language instructions require very less time
for their execution.
Disadvantages
•Low-level language instructions are very difficult to use
and understand.
•Low-level language instructions are machine-dependent,
that means a program written for a particular machine
does not execute on another machine.
•In low-level language, there is more chance for errors
and it is very difficult to find errors, debug and modify.
Middle-Level Language (Assembly Language)
• Middle-level language is a computer language in which the
instructions are created using symbols such as letters, digits and
special characters.
• Assembly language is an example of middle-level language. In
assembly language, we use predefined words called mnemonics.
• Binary code instructions in low-level language are replaced with
mnemonics and operands in middle-level language. But the computer
cannot understand mnemonics, so we use a translator
called Assembler to translate mnemonics into binary language.
• Assembler is a translator which takes assembly code as input
and produces machine code as output. That means, the
computer cannot understand middle-level language, so it
needs to be translated into a low-level language to make it
understandable by the computer.
• Assembler is used to translate middle-level language into
low-level language.
Advantages
• Writing instructions in a middle-level language is easier than writing
instructions in a low-level language.
• Middle-level language is more readable compared to low-level
language.
• Easy to understand, find errors and modify.
Disadvantages
• Middle-level language is specific to a particular machine
architecture, that means it is machine-dependent.
• Middle-level language needs to be translated into low-level
language.
• Middle-level language executes slower compared to low-level
language.
High-Level Language
• A high-level language is a computer language which can be
understood by the users.
• The high-level language is very similar to human languages and has a
set of grammar rules that are used to make instructions more easily.
• Every high-level language has a set of predefined words known as
Keywords and a set of rules known as Syntax to create instructions.
• The high-level language is easier to understand for the users but the
computer can not understand it.
• High-level language needs to be converted into the low-level language
to make it understandable by the computer.
• We use Compiler or interpreter to convert high-level language
to low-level language.
• Languages like COBOL, FORTRAN, BASIC, C, C++, JAVA,
etc., are examples of high-level languages.
• All these programming languages use human-understandable
language like English to write program instructions.
• These instructions are converted to low-level language by the
compiler so that it can be understood by the computer.
Advantages
• Writing instructions in a high-level language is easier.
• A high-level language is more readable and understandable.
• The programs created using high-level language runs on different
machines with little change or no change.
• Easy to understand, create programs, find errors and modify.
Disadvantages
• High-level language needs to be translated into low-level language.
• High-level language executes slower compared to middle and
low-level languages.
Understanding Computer Languages
The following figure provides a few key points related to computer languages.
From the above figure, we can observe the following key points...
•The programming languages like C, C++, Java, etc., are written in
High-level language which is more comfortable for the developers.
•A high-level language is closer to the users.
•Low-level language is closer to the computer. Computer hardware can
understand only the low-level language (Machine Language).
•The program written in the high-level language needs to be converted
to low-level language to make communication between the user and
the computer.
•Middle-level language is not closer to both user and computer. We
can consider it as a combination of both high-level language and
low-level language.
Creating and Running C Program
To create and execute C programs in the Windows Operating System, we need to
install Turbo C software. We use the following steps to create and execute C
programs in Windows OS…
Execution Process of a C Program
When we execute a C program it undergoes with the following
process…
Important Points
• C program file (Source file) must save with .c extension.
• The compiler converts complete program at a time from
high-level language to low-level language.
• Input to the compiler is .c file and output from the compiler
is .exe file, but it also generates .obj file in this process.
• The compiler converts the file only if there are no errors in
the source code.
• CPU places the result in User Screen window.