Module -1
Module -1
Module-1
Chapter 1
Today computers can be seen in schools, offices and almost everywhere. Computers
have gone through many stages of evolution. Some of the early computing machines
are as follows:
• Abacus emerged about 5000 years ago in Asia minor is considered as the first
computer.
• First mechanical adding device Pascaline was invented by Blaise Pascal in 1642.
It used a base of 10 to perform calculations. Drawback was it could perform only
addition.
2. COMPUTER GENERATIONS
Strech by IBM and LARC by Sperry-Rand were super computers of this generation
made by using Transistor Technology.
Jack Kilby an engineer with Texas instruments, developed the Integrated Circuit (IC) in
1958. Operating Systems were developed which allowed to run multiple programs at
once.
• Development of supercomputers.
3. Computer Types
Micro computers:
Microcomputers are the smallest category of computers fabricated using a
microprocessor and other integrated circuits namely Ram and I/O interfaces. It
can perform simple tasks like word processing or spreadsheet calculations. It is
also known as Personal Computer (PC). The first PC was built by IBM.
Minicomputers:
Minicomputers are relatively fast but small computers with limited Input/output
capabilities. These are designed for real time dedicated applications or multiuser
applications. Minicomputer is a multiprocessor system. Digital alpha and sun
ultra are some of the minicomputers.
Mainframes:
Mainframes are a large multiuser computer system designed to handle massive
amounts of input, output, and storage. Applications that require high
performance and large amount of data processing use mainframe computers.
Example: IBM S/390. Mainframes are commonly used in Banking sector.
Super computers:
Super computers are the largest, fastest, and most powerful computers. These
are expensive and have massive parallel processing capabilities. Example: IBM’s
deep blue. NASA uses a no. of super computers.
The CPU is known as the brain of the computer. The CPU interprets the instructions in
the program and executes them one by one and produces the desired result.
Control Unit.
Arithmetic and Logic Unit.
Registers
Control Unit: It controls and directs the transfer of data and program instructions
between various units.
• Fetches an Instruction.
Arithmetic and Logic Unit (ALU): ALU performs arithmetic operations, logical
operations, Relational operations and controls the speed of these operations.
Registers: They are high speed temporary storage units of CPU.
Memory Unit: Memory unit is the only storage area in a computer. Memory unit stores
data, instructions, intermediate results, and final output generated. Secondary storage
The CPU is known as the brain of the computer. The CPU interprets the instructions in
the program and executes them one by one and produces the desired result.
Control Unit.
Arithmetic and Logic Unit.
Registers
Control Unit: It controls and directs the transfer of data and program instructions
between various units.
• Fetches an Instruction.
Arithmetic and Logic Unit (ALU): ALU performs arithmetic operations, logical
operations, Relational operations and controls the speed of these operations.
Registers: They are high speed temporary storage units of CPU.
Memory Unit: Memory unit is the only storage area in a computer. Memory unit stores
data, instructions, intermediate results, and final output generated. Secondary storage
The input unit may consist of one or more input devices such as keyboard and mouse.
Output Unit: The output unit displays the results in user understandable form. ex:
monitor, printers etc.
6. PRIMARY MEMORY
Cache memory is a small fast memory which increases the performance of the
system by storing frequently used program code or data.
The above fig shows the working of cache memory. When a program is running
and CPU needs to read data or program instructions from RAM, it first checks
the Cache Memory for the data. If data is not there in cache, the CPU will read
the data from RAM into its registers and loads a copy into cache memory for
future use.
6.2 Random Access Memory (RAM) is also referred to as main memory of the
computer. The user can write Information into as well as read information from RAM.
RAM is Volatile, that is, the information in RAM is retained as long as power supply is
ON.
Types of RAM:
• SRAM: Static Random Access Memory is fast and expensive. It need not be
refreshed. It has multiple transistors for each memory cell.
• DRAM: Dynamic Random Access Memory is slower than SRAM. It needs to
be refreshed. It has single transistor and capacitor for each memory cell.
• SDRAM: Synchronous Dynamic Random Access Memory is a special type of
DRAM that is synchronised with the system clock. it has better efficiency.
• DDR-SDRAM: In Double Data Rate SDRAM the data transfer rate is twice
that of SDRAM. It works similar to SDRAM.
i)PROM:
ii)EPROM:
It stands for Erasable ROM. The contents of EPROM are erased by Exposing it to
Ultraviolet light for about 20 minutes. EPROM IC must be removed from the
computer to erase contents and all the contents are erased at once. In EPROM
we cannot erase selected Memory locations. It is cheaper and reliable.
iii)EEPROM:
6.4 Registers:
They are high speed temporary storage units of CPU used to store instructions
and intermediate data or results temporarily during processing.
7. SECONDARY MEMORY
8. INPUT DEVICES
Input devices are the devices attached to computer which are used to accept the data
and instructions from the outside world or user. Keyboard and mouse are most
commonly used input devices.
KEYBOARD: Keyboard is the most commonly used, simple to operate and cost-effective
input device.
ii)Special keys.
iii)Function keys.
MOUSE: MOUSE stands for Mechanically Operated User Serial Engine. It is an Input
device which is Used as a Pointing Device. It was developed at Stanford Research
Institute.
Scanner is a direct entry input device that can be moved over photograph or any
document and it converts the data That has been scanned into digital format. It
Eliminates duplication of data, reduces human efforts and improves accuracy and
performance.
9. OUPUT DEVICES
LCD MONITORS - Most of computers today uses LCD monitors (or their variants, LED
and TFT). An LCD screen comprises thousands of liquid crystals, which by themselves,
do not generate light but may allow or block the passage of light through them. An
image is formed by selectively applying a voltage to these crystals and using a separate
light source for light to pass through them. The backlight is provided by fluorescent
light.
IMPACT PRINTERS:
Printer is hard copy output device that produces text and graphics on a physical
medium like paper.
The printers which use a print head mechanism that strikes an inked ribbon located
between the print head and the paper print are called impact printers.
The following are the specifications of two commonly used impact printers:
Dot-matrix printer:
• An impact printer.
• print head has 9-24 pins.
• speed 30-300 characters per second.
• buffer size varies from 1k-64k.
Line printer:
• An impact printer
• Contains chain of characters or pins
• Low quality print
• prints entire line at a time
• High speed printer
Non impact printers include all printers in which print head does not make contact
with the paper and no inked ribbon is used to print.
The following are the specifications of different types of non impact printers:
Ink-jet printer:
• A non impact printer
• Prints high quality text, graphics and colour images.
• Speed 1-12 pages per minute
• Buffer size varies from 1Mb-4Mb
• Resolution 300 dots per inch
Laser:
• A non impact printer.
• Prints very high-quality text and graphics.
• Speed 4-24 pages per minute.
• Buffer size varies from 4Mb-32Mb.
• Resolution 600-1200 dots per inch.
Plotters
Plotters are a special kind of device, which are used to print large format images, such
as engineering or construction drawings created in CAD systems.
• Pen plotters.
• Ink jet plotters.
• Electro static plotters.
• Thermal plotters.
Software
Software is a collection of computer programs and related data that provide the
instruction for telling a computer what to do and how to do it. A software is an
interface between user and computer. It is a set of instructions, programs that are used
to give command to hardware. It is responsible for controlling, integrating and
managing the hardware components of a computer system and for accomplishing
specific tasks.
Types of Software
System Software
System software consists of several programs, which are directly responsible for
controlling, integrating and managing the individual hardware components of a
computer system.
It also provides the interface between the user and component of the computer.
The purpose of system software is to insulate the applications programmer as
much as possible from the detail of the particular complex computer being used.
Depending on the functionality, the system software can be further divided into
two major categories; system management program and developing software.
Operating System:
It consists of programs, which controls, which controls, coordinates, and
supervises the activities of the various components of a computer system. Its
function is to provide link between the computer hardware and the user.
Dept. of CSE, CEC 23
2. It makes sure that programs running at the same time do not interfere with each
other.
3. It is also responsible for security, ensuring that unauthorized users do not access
the system
BIOS:
The Basic Input / Output system (BIOS) is commonly known as System Bios. The BIOS
controls various electronic components within the main computer system. The initial
function of the BIOS is to initialize system devices such as the RAM, hard disk,
CD/DVD drive, video display card and other hardware. The BIOS sets the machine
hardware into a known state that helps the operating system to configure the hardware
components. This process is known as Booting Up.
Device Drivers:
A software, which is written with the objective of making a device functional when it is
connected to the computer is called device driver. It is a system software that acts like
an interface between the device and the user. Every device, whether it is a printer,
monitor, mouse or keyboard has a driver program associated with it for its proper
functioning.
▪ Device drivers are not independent programs, they assist and are assisted by the
operating system for the proper functioning.
Programming Languages
A programming language is a primary interface of a programmer with a computer. A
programming language is an artificial language to express computation that can be
performed by a computer.
Each language has its own syntax i.e., the set of specific rules and expresses the logical
steps of an algorithm. programming languages are divided into two categories: Low
Level Language (LLL) and High-Level Language (HLL).
Low Level Language (LLL) Low level language is divided into two parts
Language Translator:
2. Compiler It is used to convert the source code (written in high level language) into
machine language. Compiler reads whole source code at a time and trap the
errors and inform to programmer. For each high level language, the machine
requires a separate compiler.
3. Interpreter This language processor converts a high level language program into
machine language by converting it line-by-line. If there is any error in any line
during execution, it will report it at the same time and cannot resume until the
error is rectified.
Linker:
A linker is a system program that links together several object modules and libraries to
form a single and coherent program (executable). The main purpose of linker is to
resolve references among files. Linker is used to determine the memory locations that
code from each module will occupy and relates its instruction by adjusting absolute
references.
Loader:
Loader is a kind of system software, which is responsible for loading and relocation of
the executable program in the main memory. It is a part of operating system that
brings an executable file residing on disk into memory and starts its execution process.
Application Software
Application software is a computer software designed to help the user to perform
singular or multiple tasks. It is a set of instructions or program designed for specific
uses or applications, that enable the user to interact with a computer. Application
software are also called the end-user programs. These programs do the real work for
users. Ex: Office Software, Database Software, Entertainment software.
13. Overview of C
C is a programming language developed at AT & T’ s Bell laboratories of USA in 1972. It
was designed and written by a system programmer Dennis Ritchie. The main intention
was to develop a language for solve all possible applications.
History of C
The root of all modern languages is ALGOL, introduced in the early 1960s.
ALGOL(Algorithmic Language) was the first computer language to use a block
structure. ALGOL gave the concept of structured programming to the com[puter
science community.
Importance of C
It is a robust language whose rich set of built – in functions and operators can be
used to write any complex program.
Programs written in C are efficient and fast.
C is highly poratble. This means that C programs written for one computer can
be run on another with little or no modification.
C has its ability to extend itself.
Dept. of CSE, CEC 29
The documentation section consists of a set of comment lines giving the name of the
program, the name author and other details which the programmer would like to use
later. The link section provides instructions to the compiler to link functions from the
system library. The definition section contains all symbolic constants. There are some
variables that are used in more than one function. Such variables are called global
variables and are declared in the global declaration section.
Every C program must have one main() function section. This section contains two
parts: Declaration and Executable part.
The declaration part declares all the variables used in the executable part. There should
be at least one statement in the executable part.
These two parts must appear between the opening ‘{‘ and ‘}’ closing braces. The program
execution begins at the opening brace and ends at the closing brace.
The closing brace of the main function section is logical end of the program. All
statements in the declaration and executable parts end with a semicolon.
The subprogram section contains all the user-defined functions that are called in the
main function. The main function is very important compared to other sections.
Sample C program:
/*Program Prog1.c: Program to display a message*/
#include<stdio.h>
void main()
{
printf(“Hello”);
}
Output:
Hello
Character Set
The characters that can be used to form words, numbers and expressions depend
upon the computer on which the program is run. The characters in C are grouped
into the following categories.
Types of tokens in C:
Keywords
Identifiers
Constants
Constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals.
Dept. of CSE, CEC 33
Dept of CSE, AJIET Mangalore
Principles of Programming using C
Integer Constants:
An integer constant refers to a sequence of digits. There are three types of integers,
namely decimal, octal and hexadecimal. Decimal integers consist of a set of digits
0 through 9, preceded by an optional – or + sign. Some examples of decimal integer
constants are:
123
-431
0
34567
+678
Spaces, commas, and non-digit characters are not permitted between digits. For
example:
15 750
20,000
Rs 1000
An octal integer constant consists of any combination of digits from the set 0
through 7 with a leading 0. Some examples are:
037
0
0435
0567
represent the numbers 10 through 15. The examples for hexadecimal integers are:
0x2
0x9
F
0xbc
d 0x
Floating-point constants:
Integer numbers are inadequate to represent quantities that vary continuously, such
as distances, heights, temperatures, prices and so on. These quantities are
represented by numbers containing fractional parts like 23.78. Such numbers are
called floating-point constants or real constants. Examples for floating-point
constants are given below.
213.
.95
-.71
+.5
A real number may also be expressed in exponential (or specific notation). For
example the value 213.45 may be written as 2.1345e2 in exponential notation. e2
Character Constants:
A character constant contains a single character enclosed within a pair of single
quote marks. Examples of character constants are: ‘5’ ‘X’ ‘;’ ‘ ‘
Note that the character constant ‘5’ is not the same as the number 5. The last
constant is a blank space. Character constants have integer values known as
ASCII values.
For Example:
Note that each one of them represents one character, although they consist of two
characters. These character combinations are called escape sequences.
String constants:
A string constant is a sequence of characters enclosed in double quotes. The letters
may be numbers, special characters and blank space.
Meaning of variables:
A variable is a data name that may be used to store a data value. Unlike the
constants that remain unchanged during the execution of a program, a variable
may take different values at different times during execution. A variable name can
be chosen by the programmer in a meaningful way to reflect its function or nature
in the program. Some examples are given below.
Average
Height
Total
Counter
_1
Variable Definition
A variable definition tells the compiler where and how much storage to create for the
variable. A variable definition specifies a data type and contains a list of one or more
variables.
Declaration of variables:
Declaration should appear at the beginning of a program before the variable names
are used.
Syntax:
data_type variable_name;
where data_type can be any basic or derived datatypes like int, float, short, char
etc. varibale_name can be any valid identifier.
Ex:
int
number;
float rate;
char
grade;
When a variable name is declared then a memory location is identified and given this
name.
Variable Initialization:
The process of assigning initial values to a variable during declaration is called
as variable initialization. Syntax:
datatype variable1=value;
Ex: We can initialize a variable called num1 of type int with the vale 10 as follows:
int num1=10;
We can initialize two variables with names length and breadth, both of type float
with values 15 and 20 respectively as:
Integer Types:
Integers are whole numbers with a range of values supported by a particular
machine.
Generally integers occupy one word of storage. If we use a 16 bit word length,
the size of the integer value is limited to the range -32768 to +32767.
A signed integer uses one bit for sign and 15 bits for the magnitude of
the number.
Similarly, a 32 bit word length can store an integer ranging from -
2,147,483,648 to 2,147,483,647.
C has three classes of integer storage both unsigned and signed forms.
– short int
– int
– long int
For example, short int represents fairly small integer. Values and requires half
the amount of storage as a regular int number uses.
Unlike signed integers, unsigned integers use all the bits for the magnitude of
the number and are always positive.
Therefore, for a 16 bit machine, the range of unsigned integer numbers will be
from 0 to 65,535. We declare long and unsigned integers to increase the range of
values.
Floating point types:
Floating point (or real) numbers are stored in 32 bits (on all 16 bit and 32 bit
machines), with 6 digits of precision.
Floating point numbers are defined in C by the keyword float.
The type double can be used when the accuracy provided by a float number is
not sufficient.
A double data type number uses 64 bits giving a precision of 15 digits. These
are known as double precision numbers.
To extend the precision further, we may use long double which 80 bits.
Character types:
A single character can be defined as a character (char) type data.
Characters are usually stored in 8 bits (one byte) of internal storage.
The qualifier signed or unsigned may be explicitly applied to char.
While unsigned chars have values between 0 and 255, signed chars have
values from -128 to 127.
Storage classes
A storage class defines the scope (visibility) and life-time of variables and/or
functions within a C Program. They precede the type that they modify. We have
four different storage classes in a C program –
auto
register
static
extern
The auto Storage Class
The auto storage class is the default storage class for all local variables.
void fun( )
{
int mount;
volatile variable can be modified by the program itself. This can be prevented by
using const qualifier as follows:
volatile const int location = 100;
Arithmetic Operators
The binary arithmetic operators are +, - ,*, / and the modulus operator %. The %
operator cannot be applied to float or double. The arithmetic operators *, / and %
have the higher precedence than the + and – operators.
Dept. of CSE, CEC 43
Relational Operators
The relational operators are: = = != > >= < <=. The relational
operators have lower precedence than the arithmetic operators. If a=10 and b=20
then:
Logical Operators
In Logical AND operator, if expressions on both the sides of the logical AND
operator is true, then the whole expression is true.
In Logical OR operator, if expressions on one or both the sides of the logical OR
operator is true, then the whole expression is true.
The Logical NOT operator takes a single expression and negates the value of the
expression. That is, logical NOT produces a zero if the expression evaluates to a non-
zero value and produces a 1 if the expression produces a zero.
Following table shows all the logical operators supported by C language. Assume
variable A holds 1 and variable B holds 0, then:
Assignment Operators
C provides two operators for incrementing and decrementing variables. The increment
operator ++ adds 1 to its operand, while the decrement operator -- subtracts 1.
The ++ and -- may be used either as prefix operators (before the variable, as in ++n), or
postfix (after the variable: n++). In both the cases, the effect is to increment n. But the
expression ++n increments n before its value is used, while n++ increments n after its
value has been used.
If n is 5, then
x = n++; //sets x to 5,but
x = ++n; //sets x to 6.
Dept. of CSE, CEC 46
Bitwise Operators
The bitwise AND operator is used to mask off some set of bits.
Ex: n = n & 0177; sets to zero all but low order 7 bits of n
Ex: n = n | 0011
The bitwise exclusive OR operator ^ sets a one in each bit position where other
operands have different bits, and zero where they are the same.
The shift operators << and >> perform left and right shifts of their left operand by the
number of bit positions given by the right operand, which must be positive.
Ex: x<<2, shifts the value of x left by two positions, filling the vacated bits with zero.
The unary operator ~ yields the one’s complement of an integer, that is, it converts
each 1-bit into a 0-bit and vice versa.
Conditional Operators
The expression expr1 is evaluated first. I it is non-zero (true), then the expression
expr2 is evaluated, and that is the value of the conditional expression. Otherwise
expr3 is evaluated, and that is the value. Only one of expr2 and expr3 is evaluated.
Thus to set z to the maximum of a and b, we use a conditional operator as:
z=(a>b)?a:b;
Converting one data type to another data type is called type conversion. Two types:
Implicit type conversion
Explicit type conversion
Implicitly converting a variable from one data type to another is called as implicit type
conversion. This is automatically done by the compiler.
When an operator has operands of different types, they are converted to a common type
according to a small number of rules:
Consider the following code in which an integer data type is promoted to float. This is
known as promotion (when a lower level data type is promoted to a higher type).
float x;
int y = 3;
x = y;
Now, x = 3.0, as the integer value is automatically converted into its equivalent floating
point representation.
float f = 3.5;
int i;
i = f;
The statement i = f results in f to be demoted to type int, ie., the fractional part of f will
be lost and I will contain 3 (not 3.5). In this case demotion takes place i.e., a higher
level data type is converted into a lower type.
Explicit Type Conversion can be forced (“coerced”) in any expression, with a unary
operator called a cast.
In the construction, (type-name) expression
The expression is converted to a forcefully to the type specified in the type name.
int a = 500, b = 70;
float res;
Ex:
res = (float) a / b;
In the above example, the value obtained by dividing a by b, will be converted
to floating number and will be stored in the variable res.
The below table summarizes the rules for precedence and associativity of all types
of operators. Operators on the same line have the same precedence; rows are in
order of decreasing precedence.
Web Resources
3. Learning to Program in C:
https://www.youtube.com/watch?v=rk2fK2IIiiQ
4. Tokens in C: https://www.youtube.com/watch?v=5De6OILHH9A
https://www.youtube.com/watch?v=vNeOx1rQ25E&t=432s
Video Resources
1. Introduction-> https://youtu.be/tMOKg2OfntU
9. Overview Of C: https://youtu.be/XDdyI3W1LPE
Question Bank
10. Write a note on different types of Type conversion, with example/program for each.
University Questions
3. Classify the following into input and output devices: Monitors, visual display unit,
track balls, Bar code reader, digital camera, film recorder, microfiche, OMR,
4. Define the terms: Network, LAN, WAN, MAN, and network topology.
5. Write the basic structure of C program. Explain each section briefly with suitable
example.
8. State whether the following are valid identifiers or not: integer, float, I am,
123_AbC.