Module 1 Notes
Module 1 Notes
CHAPTER 1
INTRODUCTION TO COMPUTER HARDWARE AND SOFTWARE
1. INTRODUCTION
Computer is an electronic device which accepts input, processes data, stores information and produces output.
2. COMPUTER GENERATIONS
The computer of each generation is smaller, faster and more powerful than preceding generation. There are
five computer generations.
First Generation: The vacuum tubes were used for computation. Magnetic drums were used for
memory requirements. It consumed lot of space, power and generated lot of power. ENIAC (Electronic
Numerical Integrator and Computer) used 18000 vacuum tubes, 1800 acquired sq. ft. room space and
consumed 180KW of power. The machine level language (0s and 1s) was used. Punched cards were used for
input and Paper for output. They were used for scientific work.
Second Generation: The transistors was the most important component which replaced vacuum tubes.
Magnetic cores were used for memory. It were more reliable than first generation computer. The assembly or
symbolic language was used. The input and output mechanism remained same. The stored program concept
was introduced which stores both data and program.
Third Generation: The Integrated circuits(IC) was the most important component. The transistors,
diodes, resistors, capacitors were integrated on a single chip. The high-level language was used like BASIC,
C, C++ and JAVA. Memory capacity increased and magnetic hard disk was used for secondary generation.
The third generation computers also had OS and computer could rum programs invoked by multi users.
Fourth Generation: The Microprocessor was the most important component. With the help of LSI
(Large Scale Integration) and VLSI (Very Large Scale Integration) the entire CPU is on a single chip. OS have
moved from MSDOS to GUI (Graphical User Interface) like windows. The networking technology has also
been improved. The size was reduced and the speed was increased.
Fifth Generation: Artificial Intelligence and use of natural languages are the main features of this
generations. These systems are expected to interact with users in natural language. Speech recognition and
speech output should also be possible. Computers must be able to perform parallel processing. The quad-core
and octa-core was also introduced. Neural networks and expert systems have been developed.
3. COMPUTER TYPES
Apart from being classified by generations, computers can also be categorized by their size. The size of a
computer is often an indirect indication of its capabilities.
Supercomputers: These are huge machines having most powerful and fastest processors. It uses
multiple CPUs for parallel data processing. Speeds are measured in flops (floating point operations per
second). The fastest operates at 34 petaflops. They are used for weather forecasting, analysis of geological
data. They have enormous storage, uses more power and generate lot of heat. They are used by government
agencies.
Mainframes: These are multi-user machines that support many users using the feature of time sharing.
It can run multiple programs even with a single CPU. The processor speed is measured in MIPS (Million
instructions per second). It is used to handle data, applications related to organization and online transactions
in banks, financial institutions and large corporations.
Smartphones and Embedded Computers: The smartphone is a general purpose computer i.e.,
capable of making phone calls. It has a powerful processor, with multiple cores, supports GBs of memory,
and runs developed OS (Android or iOS). It can be operated with keyboard, touch or stylus.
Embedded Computers or micro-controllers are very small circuits containing a CPU, non-volatile memory,
input and output handling facilities. They are embedded into many machines that we use – cars, washing
machines, cameras etc. The processor here runs a single unmodifiable program stored in memory.
The ALU is a “super calculator” carrying out all arithmetic tasks and Boolean operations.
The CU controls the way data is moved between the various components of computer.
Both ALU and CU use the service of clock for synchronizing their Operations.
The CPU uses a few high-speed registers to store the current instruction and its data. One of the registers,
program counter, stores the address of next instruction to be executed.
All program instructions are executed using the fetch-decode-execute mechanism.
The CPUs are rated in GHz (gigahertz).
Input Unit: It is used to give the input that is data to the computer. It is done with the help of input devices.
Ex: Mouse, Keyboard
Output Unit: It is used to receive the output (information) from the computer. It is done with the help of
output devices. Ex: Printer, Speaker.
Memory: Collection of chips on motherboard, where all computer processing and program instructions are
stored. There are two types: Primary Memory and Secondary Memory.
6. PRIMARY MEMORY
Primary memory is the main memory, which stores data and programs, which are currently needed by CPU.
The size is less than the secondary memory and it is costly.
Prof. Suvika K V, Dept. of CSE, CBIT, Kolar 2020-21
3
CPPS – 18CPS13 Module 1
1. RAM (Random Access Memory): It is the main memory, where the user can write information into
RAM and read information from it. It is accessible to users. The RAM is randomly accessible by user.
It is a volatile memory, which means the data, or information is retained as long as power supply is
ON. There are two types of RAM: SRAM and DRAM.
2. ROM (Read Only Memory): It is a permanent memory that can be read but not written. It is a
nonvolatile memory, which means the data or information is retained even power supply is not there.
It contains a startup program BIOS (Basic Input Output System) which transfers control to OS.
EPROM (Erasable Programmable Read Only Memory): It can be rewritten (but only once)
even though it has been previously burned. It is erased by exposing it to UV-rays.
EEPROM (Electrically Erasable Programmable Read Only Memory): It can be erased and
rewritten multiple times. The electric voltage is used to erase the data. The pen drive we use today
is of EEPROM.
3. Cache Memory: It holds those portions of program that are frequently used by CPU. It acts as a buffer
between CPU and RAM. The CPU first looks for the instructions in cache. It executes faster than
RAM, expensive and limited in size. It has multiple levels:
L1 (Level 1) – smallest and fastest – 32 KB
L2 (Level 2) – present closer to CPU – 256 KB
L3 (Level 3) – shared by cores – 8 MB
4. Registers: The small number of ultra-fast registers integrated into the CPU represent the fastest
memory of the computer. The CPU does all its work here. Each register has the length of the computer.
The data is loaded into register before processing. Registers are numbered and a program instruction
specifies these numbers. Ex: OR1R2R3 which means multiplication operation is performed on R1 and
R2 is performed and stored in R3.
7. SECONDARY MEMORY
Secondary memory is not directly connected to CPU. It exists inside the machine and also externally. It is a
non-volatile, offline and long-term storage memory. It is slower, cheaper than primary memory but the
capacity is higher.
1. Hard disk/ Hard drive/ Fixed disk: It is the oldest secondary storage device. It has more capacity
but, the cost is less comparatively. It is commonly present in laptop with 500GB and desktop with
1TB. It contains a spindle, which holds one or more platters made up of non-magnetic material. It has
two surfaces which is coated with magnetic material. Each surface has serially numbered tracks and
further broken into sectors or blocks. The disk runs with the speed of 5400 and 7200 rpm.
2. Magnetic tape: The magnetic tape is made up of plastic film with one side coated with magnetic
material. It supports 1 TB or more, but 200 TB are also expected. The device is not fully portable
though because, a separate tape drive is required. The data is accessed sequentially. This makes it
unsuitable for backup.
3. Optical Disks (CD-ROM, DVD ROM, Blu-ray Disk): It is non-volatile read-only memory. The CD-
ROM and DVD-ROM, can hold large volumes of data (700MB to 8.5 GB). The Blu-ray disk has the
capacity upto 50 GB. A laser beam in their drives controls the read and write operations. A laser beam
is used to construct pits and lands by burning selected areas along its tracks.
CD-R, DVD-R: Data can be recorded only once.
CD-RW, DVD-RW: Data can be recorded multiple times.
4. Flash Memory: It doesn’t have any moving parts, is based on the EEPROM. It is available in various
forms- pen drive, magnetic card (SD Card), solid state disk (SSD). They are portable, need little power
and quite reliable.
The memory stick or pen drive is the most common type of flash memory used on the
computer. It is a small, removable piece of circuit and it connects to the USB port of computer.
The solid state disk is a bigger device meant to replace the traditional magnetic hard disk.
The magnetic card is used mainly in cameras and the most popular is the micro-SD card.
5. Floppy Diskette: This is represented by a rectangular plastic case containing a thin magnetic disk. It
was available in two sizes (5.25” and 3.5”), offering capacities of 1.2 MB and 1. MB. It is unsuitable
for backup purpose.
The current USB 3.0 can transfer 1 GB file in 20 seconds. The smaller variant, the micro-USB port is used in
smartphones.
SERIAL PORT: This port transfers one bit at a time serially. They are offered in 9-pin and 25-pin
configuration. They were used for connecting keyboard, mice, and modems.
PARALLEL PORT: This port is used to transfer data parallelly 8 bits at a time. This is implemented
using 25 pins and usually for printers.
VGA (Video Graphics Array): This 15-pin port allows transfer of analog video data to the monitor.
This is replaced with DVI (Digital Video Interface) which uses digital data i.e. used by flat LCD panels.
RJ45 port: This port is used by Ethernet network. Even though computer connects wirelessly, the
wired RJ45 remains as a useful option.
PS/2 port: This port has replaced serial port. It has 6 pins but occurs as a pair in two different colors.
The ports and connectors for keyboard are purple, while the mouse uses green port. USB has invaded this area
also.
HDMI (High Definition Multimedia Interface): This is used for transferring audio and video
between computers and HDTVs, projectors and home theaters.
9. INPUT DEVICES
Input devices are needed to interact with the OS to perform tasks. Ex: Keyboard, Mouse, Joystick, Stylus,
Scanner etc.
Keyboard: Every computer supports a keyboard – either a physical or touchscreen. The keyboard has
QWERTY layout and contains large number of symbols. Each letter, numeral or symbol is known as a
character, which represents smallest piece of information. Each character has a unique values called the ASCII
(American Standard Code for Information Interchange) value.
Pointing Devices: GUI (Graphical User Interfaces) like windows need a pointing device to control the
movement of cursor on the screen. This is implemented as mouse in desktop and touchpad in laptop. The
earliest form has a rotating ball and two buttons. The left button is used for selecting (by clicking once) and
execute (by clicking twice). The right button is used to check and change attributes. The optical mouse uses
infrared laser/LED, the wireless mouse uses radio frequency technology.
Scanner: A scanner is a device that creates a digital image of a document by optically scanning it. The
flatbed scanner doesn’t exceed more than A4 size. It is operated with by using special software. The document
to be scanned is placed on a glass plate covered by lid. Modern scanners have OCR (Optical Character
Recognition) facility which extracts text as a stream of characters i.e. converting image file to text file and
MICR (Magnetic Ink Character Recognition) reads the codes using hand held barcode readers.
Monitor: The monitor is an integral part of computer which displays both text and graphics. The
performance is measured in terms of image quality, resolution, energy consumption.
CRT (Cathode Ray Tube) Monitors: The CRT monitors have a rarefied tube containing three electron guns.
The guns emit electrons create images. They usually have resolution of 640*840 pixels. They are large, heavy,
energy efficient and produces lot of heat.
LCD (Liquid Crystal Display) Monitors: The image is formed by applying voltage on crystals. The
backlight is provided by fluorescent light. They consume less power, generate less heat and have increased
life span.
Impact Printers: It produces the hardcopy of output. The impact printers are old, noisy.
But, still dot-matrix printer is in usage.
Dot-Matrix Printer: The print head of the dot-matrix printer has either 9 or 24 pins. When the pins fire
against the ribbon, an impression is created on the paper. The speed is 300 cps and doesn’t produce high
quality output. It can produce multiple copies.
Daisy-wheel Printer: It employs a wheel with separate characters distributed along its outer edge. The wheels
can be changed to obtain different set of fonts.
Line Printer: For heavy printing, the line printer is used. It uses a print chain containing the characters.
Hammers strike the paper to print and it rotates at the speed of 1200 lpm. It is also noisy and is of low-quality.
Non-Impact Printers: They are fast, quiet and of high resolution. The most commonly used non-
impact printers are laser and ink-jet printers. The thermal printer is not discussed here because it uses heat to
print on high-sensitive paper.
Laser Printer: It works like a photocopier and uses toner i.e. black magnetic powder. The image is created
in the form of dots and passed from drums on to the paper. It has built-in RAM which acts as buffer and RAM
to store fonts. The resolution varies from 300 dpi to 1200 dpi and the speed is about 20 ppm.
Ink-jet Printer: These are affordable printers. It sprays tiny drops of ink at high pressure as it moves along
the paper. The separate cartridges are available for different colors. The resolution is about 300 dpi, can print
1 to 6 pages/min.
Plotters: The plotter can make drawings. It uses one or more automated pens. The commands are
taken from special file called vector graphic files. Depending on type of plotter either paper or pen moves. It
can handle large paper sizes and it is used for creative drawings like buildings and machines. They are slow
and expensive.
Network Topology: The ways used to connect the computers. The different types are: Bus, Star, Ring, and
Mesh.
Network Types: Networks are also classified on their size. The most common types are LAN and
WAN. And some other types are: MAN, CAN and PAN.
1. LAN (Local Area Network): They are used in smaller organizations usually using Ethernet. The usual
speed will be 100Mbps.
2. WAN (Wide Area Network): They are used in cities and can connect larger distance. They use optic
fiber cables. Banks, Airline and Hotel reservations use WANs.
3. MAN (Metropolitan Area Network): It is sandwiched between LAN and WAN and used for
interconnecting in same cities.
4. PAN (Personal Area Network): This is the smallest network and can connect only few meters. It
connects small devices like phones, laptops through Bluetooth.
Intranet is a network of computers designed for a specific group of users and can be accessed from
Internet but with restrictions.
Internet is wide network of computers and is open for all and itself contains a large number of
intranets.
SWITCH will have a table which contains MAC addresses of connected devices. The data is sent after looking
up the table for destination.
Bridge and Router: The network supports many nodes which leads to congestion. Hence, the network
may be split into a number of segments, with a BRIDGE connecting them. It connects two networks using the
same protocol. ROUTER connects two similar or dissimilar networks separated by long distance. It is a part
of two networks and thus have two addresses. It has a routing table to store address.
Software is a collection of code that drives a computer to perform related group of tasks.
Programs in software use a language.
The source code is created by programmer using programming languages like C, C++, Java, Python etc.
The software is developed to operate on multiple platforms.
SOFTWARE TYPES
Computer software can be broadly classified into two types: System software and Application Software.
System Software: Software run by the computer to manage the hardware connected to it is known as
system software. System software examples:
BIOS- It checks the hardware devices and peripherals at boot time.
OS: It manages both hardware and programs running on the computer.
Application Software: Software not directly connected with hardware but related to a specific
application is known as application software. Application software examples:
Office software: This comprises of three separate applications: word processing, spread sheet and
presentations.
Database software: It allows data to have a uniform structure to be stored in a database.
CHAPTER 2: INTRODUCTION TO C
1. PSEUDOCODE
Pseudocode is an informal list of steps in English like statements which is intended for human reading.
It is used in planning of computer program development, for sketching out the structure of the program
before the actual coding takes place.
Advantages:
Disadvantages:
1. There is no standard form.
2. One Pseudocode may vary from other for same problem statement.
Examples:
1. Begin 1. Begin
2. Read two numbers a, b 2. Read the values of length, breadth
3. Calculate sum = a+b 3. Calculate area = l x b
4. Display sum 4. Display area
5. End 5. End
2. HISTORY OF C
Characteristics of C:
C is easy to learn.
C is a general purpose language.
C is a structured and procedural language.
It is portable.
It can extend itself.
Examples of C:
Operating system
Language compilers
Assemblers
Text editors
Databases
A C character set defines the valid characters that can be used in a source program. The basic C character
set are:
1. Letters: Uppercase: A,B,C,….,Z
Lowercase: a,b,c,…..,z
2. Digits: 0,1,2,…..,9
3. Special characters: ! , . # $ ( ) } { etc
4. White spaces: Blank space, Horizontal tab space (\t), carriage return, new line character (\n), form feed
character.
4. C – TOKENS
i. Keywords
ii. Identifiers
iii. Constants
Constants are the values that doesn’t changes during the execution of a program.
Integer Constant
Numeric
Constant
Real Constant
Constant
Single Character
Constant
Character
Constant
String Constant
Numerical Constant
3. Hexadecimal: It is an integer constant consisting of numbers from 0-9, A-F (A=10, B=11, C=12,
D=13, E=14, F=15). It is preceded by 0x
Real Constant:
Character Constant
String Constant:
A group of characters together form string.
Strings are enclosed within double quotes.
They end with NULL character (\0).
Ex: “CBIT”
C B I T \0
NOTE:
Qualified Constant/ Memory Constant: These are created by using “const” qualifier. Const means that
something can only be read but not modified.
Syntax: const datatype variable_name = value;
Ex: const int a = 10;
const float pi = 3.14;
Symbolic Constants/ Defined Constant: These are created with the help of define preprocessor
directive.
Ex: #define PT 3.142
During processing the PI in the program will be replaced with 3.142.
The name of constant is written in uppercase just to differentiate from the variables.
iv. Strings
C P P S \0
V. Operators
An operator is a symbol that tells the compiler to perform specific mathematical and logical functions.
The different operators supported in ‘C’ are:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operators
6. Unary Operators Increment and Decrement
7. Ternary/ Conditional Operator
8. Special Operators
2. Relational Operators: These are used to compare two quantities. The output will be either 0 (False)
or 1 (True). The different relational operators are:
3. Logical Operators: These are used to test more than one condition and make decision. The different
logical operators are: NOT, AND, OR
Logical NOT (!) The output is true when input is false and vice versa. It accepts only one
input.
Input Output
X !X
0 1
1 0
Logical AND (&&) The output is true only if both inputs are true. It accepts two or more
inputs.
Input Output
X Y X && Y
0 0 0
0 1 0
1 0 0
1 1 1
Logical OR (||) The output is true only if any of its input is true. It accepts two or more inputs.
Input Output
X Y X || Y
0 0 0
0 1 1
1 0 1
1 1 1
4. Assignment Operators: These are used to assign the result or values to a variable. The different types
of assignment operators are:
Simple Assignment a = 10
Shorthand Assignment a += 10 a = a + 10
Multiple Assignment a = b = c = 10
5. Bitwise Operators: These works on bits and performs bit by bit operations. The different types of
bitwise operators are:
i. Bitwise NOT (~)
ii. Bitwise AND (&)
iii. Bitwise OR (|)
iv. Bitwise XOR (^) Output is True when odd number of 1’s are present.
v. Bitwise left shift (<<)
vi. Bitwise right shift (>>)
X ~X
0 1
1 0
Bitwise Left Shift (<<) Shift specified number of bits to left side.
X 0 1 0 0 0 1 1 0
X<<2 0 0 0 1 1 0 0 0
Bitwise Right Shift (>>) Shift specified number of bits to right side.
X 0 1 0 0 0 1 1 0
X>>2 0 0 0 1 0 0 0 1
Pre-increment Post-increment
First value of the operand is incremented First value of the operand is used for evaluation
(added) by 1 then, it is used for evaluation. then, it is incremented (added) by 1.
Ex: ++a Ex: a++
5. EXPRESSIONS
=
*= /= %=
+= -= &= Assignment operators Right to left 14
^= |=
<<= >>=
, Comma operator Left to right 15
6. DATA TYPES
Primary/ Built-in/ Fundamental data type: These are the built in data types available in C. There are
5 types. Namely:
1. Integer (int)
2. Floating point (float)
3. Character (char)
4. Double precision floating point (double)
5. Void (void)
1. Integer type:
It is used to store whole numbers.
The keyword int is used to declare variable of integer type.
Int type takes 2B or 4B of storage depending on machine size.
The classes of integer are:
Unsigned Signed
Data type Keyword Size Data type Keyword Size
Short Integer short int 1B Signed short integer signed short int 1B
Integer int 2B Signed integer signed int 2B
Long Integer long int 4B Long integer long int 4B
3. Double:
It is used to store double precision floating point numbers.
The keyword double is used to declare variable of floating point data type.
Double type takes 8B of storage.
Double precision is related to accuracy of data.
4. Char:
It is used to store character type of data.
The keyword char is used to declare variable of character type.
Char type takes 1B of storage.
5. Void:
It is a special data type that has no value.
It doesn’t have size.
It is used for returning the result of function that returns nothing.
7. VARIABLES
A variable is a name given to memory location whose value changes during execution.
Declaration:
Initialization:
8. TYPE CONVERSION
Converting the value of one data type to another type is called as Type Conversion.
It occurs when mixed data occurs.
There are two types:
Here, the operand/ variables of smaller data type is automatically converted to data type of larger
size.
char int long int float double long double
Ex: int a = 5;
float b = 25, c; a b c
c = a / b; 5 25.0 0.25
printf(“%f” , c);
It is a forced conversion used to convert operand/ variables of larger data type to smaller size or
vice versa.
Ex: int a = 7, c; a b c
float b = 4.0; 7 4.0 3
b = a % (int) b; b Converted into int & evaluated
printf(“%d” , c);
Link Section: It provides instruction to the compiler to link functions from system library.
Definition Section: It defines all symbolic constants.
Global Declaration Section: The variables which are used in more than one function are called global
variables and are declared in this section.
main( ) Section: Every ‘C’ program has one main( ) function and it contains two parts:
i. Declaration Part: Here, all the variables used are declared.
ii. Executable Part: Here, it contains at least one executable statement.
The main( ) function is enclosed within flower brackets and the statements ends with semicolon.
Sub-program Section: It contains all the user defined functions that are called by main( ) function.
Documentation section
Link section
Definition section
Global declaration section
main( ) Section
{
Declaration part
Executable part
}
Sub program section
Function 1
Function 2
-
-
Function n
Example:
Questions:
1. Evaluate each of the following expression independent of each other.
i. x = a – b/3 + c * 2 – 1 where, a=9, b=12, c=3
ii. 10 != 10 || 5 < 4 && 8
iii. 100%20 <= 20 – 5 + 100 % 10 – 20 = = 5 >=1 != 20
iv. a += b * = c - = 5 where, a = 3, b=5 and c=8
v. int i=3, j=4, k=2
a) i++ - j
b) ++k % --j
c) j+1/i-1
d) j++/i--
vi. 22+3 < 6 && !5 || 22 == 7 && 22-2 > +5
vii. A+2 b || !c && a ==d*a-2<=e where, a=11, b=6, c=0, d=7 and e=5
𝑦
vii) m = 𝑥 4 + √𝑥 + − 4𝑥 + 6
𝑘
Example Programs:
Algorithm Flowchart
Program Output
#include<stdio.h> Enter length and breadth
{
2
int l, b, area, peri;
printf(“Enter length and breadth\n”); 4
scanf(“%d%d”, &l, &b);
The area is 8
area = l * b;
peri = 2 * (l + b); The perimeter is 12
printf(“The area is %d\n”, area);
printf(“The perimeter is %d\n”, peri);
}
Algorithm Flowchart
Program Output
#include<stdio.h> Enter principle, rate and time
{
1000
float p, t, r, si;
printf(“Enter principle, time and rate\n”); 2
scanf(“%f%f%f”, &p,&t,&r);
4
si = p * t * r / 100;
printf(“The Simple Interest is %f”, si); The Simple Interest is 80
}