Module-1 Intoduction To Computer Hardware and Software, Overview of C
Module-1 Intoduction To Computer Hardware and Software, Overview of C
22POP13
MODULE-1
INTODUCTION TO COMPUTER HARDWARE AND SOFTWARE,
OVERVIEW OF C
Computers are such an integral part of our everyday life now most people take them and
what they have added to life totally for granted.
The history of the computer goes back several decades however and there are five definable
generations of computers.
These first generation computers relied on ‘machine language’ (which is the most basic
programming language that can be understood by computers). These computers were limited
to solving one problem at a time. Input was based on punched cards and paper tape. Output
came out on print-outs. The two notable machines of this era were the UNIVAC and ENIAC
machines – the UNIVAC is the first every commercial computer which was purchased in 1951
by a business – the US Census Bureau.
The language evolved from cryptic binary language to symbolic (‘assembly’) languages. This
meant programmers could create instructions in words. About the same time high level
programming languages were being developed (early versions of COBOL and FORTRAN).
Transistor-driven machines were the first computers to store instructions into their memories
– moving from magnetic drum to magnetic core ‘technology’. The early versions of these
machines were developed for the atomic energy industry.
By this phase, transistors were now being miniaturised and put on silicon chips (called
semiconductors). This led to a massive increase in speed and efficiency of these machines.
These were the first computers where users interacted using keyboards and monitors which
interfaced with an operating system, a significant leap up from the punch cards and printouts.
This enabled these machines to run several applications at once using a central program which
functioned to monitor memory.
As a result of these advances which again made machines cheaper and smaller, a new mass
market of users emerged during the ‘60s.This generation of computers also had an operating
system which is a special program meant to control the resources of the computer. By virtue of
feature known as time sharing, the computer could run programs invoked by multiple users.
The existing programming languages were supplemented by BASIC, C, C++ and Java.
This revolution can be summed in one word: Intel. The chip-maker developed the Intel 4004
chip in 1971, which positioned all computer components (CPU, memory, input/output controls)
onto a single chip. What filled a room in the 1940s now fit in the palm of the hand. The Intel
chip housed thousands of integrated circuits. The year 1981 saw the first ever computer (IBM)
specifically designed for home use and 1984 saw the MacIntosh introduced by Apple.
Microprocessors even moved beyond the realm of computers and into an increasing number of
everyday products.
The increased power of these small computers meant they could be linked, creating networks.
Which ultimately led to the development, birth and rapid evolution of the Internet. Other major
advances during this period have been the Graphical user interface (GUI), the mouse and more
recently the astounding advances in lap-top capability and hand-held devices.
Computer devices with artificial intelligence are still in development, but some of these
technologies are beginning to emerge and be used such as voice recognition.
AI is a reality made possible by using parallel processing and superconductors. Leaning to the
future, computers will be radically transformed again by quantum computation, molecular and
nano technology.
The essence of fifth generation will be using these technologies to ultimately create machines
which can process and respond to natural language, and have capability to learn and organise
themselves.
Computer Types:-
Super Computer:-
These are huge machines having most powerful and fast processors. A super computer has
multiple CPUs for parallel data processing. Speed is measured in terms of flops(floating point
operations per second)
super computers are too powerful to be used for transaction processing. They are mainly used
in the areas like weather forecasting, analysis of geological data, nuclear simulation and space
exploration. They are also used to solve complex scientific problems. Super computers have
enormous storage and use huge amounts of power and generate a lot of heat. because of the
exorbitant cost, they are mainly used by government agencies
Main frames:-
Mainframe is very large in size and is an expensive computer capable of supporting hundreds
or even thousands of users simultaneously. Mainframe executes many programs concurrently
and supports many simultaneous execution of programs.
Mainframes are used to handle data and application related to the organisation as a whole.
Today, main frames are employed to handle online transactions, the capability to handle large
amount of data makes the main frame suitable for use in government, banks and financial
institutions and large corporations.
Minicomputers:-
Computer that is smaller, less expensive, and less powerful than a mainframe or supercomputer
but more expensive and more powerful than a personal computer. Minicomputers are used for
scientific and engineering computations, business-transaction processing, file handling, and
database management, and are often now referred to as small or midsize servers.
Microcomputers:-
and auxiliary storage units. Smaller microcomputers first marketed in the 1970s contain a
single chip on which all CPU, memory, and interface circuits are integrated.
They are mainly used for engineering and scientific applications and for software development
along with word processing, desktop publishing, internet browsing and can also handle audio,
video and image files
Smartphones are a class of mobile phones and of multi-purpose mobile computing devices.
They are distinguished from feature phones by their stronger hardware capabilities and
extensive mobile operating systems, which facilitate wider software, internet (including web
browsing over mobile broadband ), and multimedia functionality (including music, video,
cameras and gaming ), alongside core phone functions such asvoice calls and text messaging.
Smartphones typically contain a number ofmetal-oxide-semiconductor (MOS) integrated
circuit (IC) chips, include various sensors that can be leveraged by their software,and support
wireless communications protocols (such as Bluetooth. Wi-Fi or satellite navigation) .
Bit is short for 'binary digit.' It's a single digit in a binary number, and it can be either 1 or 0.
A byte is 8 bits. That's the definition. With 8 bits you can store any number between 0 and 255,
since there are 256 different combinations of 1 and 0 to choose from.
Why eight bits? The original intention was that, when storing text, 8 bits would be enough to
assign a unique number every possible language character you might want to use in your
document. The idea was that each character in a file would take up one byte of memory
A word is basically the number of bits a particular computer's CPU can deal with in one go. It
varies depending on the computer architecture you're using.
INSIDE THE COMPUTER:-
The brain of the computer is the Central Processing Unit (CPU) represented by a single chip
on a PC. The CPU carries out every instruction stored in a program while interacting with other
agencies as and when necessary. Most of the work is done by the Arithmetic and Logic unit
(ALU) which is the integral part of the CPU
The CPU needs both fast and slow memory to work with. Fast memory is represented by
primary memory known as Random Access Memory (RAM). It is divided into number of
contiguously numbered cells. The number represents the address of the cell. The primary
memory is used for storing instructions and data of the program currently in execution.
The Computer also supports slower secondary memory called secondary storage or auxiliary
memory. This can generally be a hard disk or a CD-ROM or a DVD-ROM. Secondary memory
is used to store the data not required currently. Data in secondary memory are stored as files
having unique names. The program is executed by loading instructions and data from
secondary memory to primary memory. User interact with the computer system using input
and output devices. There are three types of data thst move between the various compnants of
the computer. the data of a specific type move along a distinct path way called bus. The program
instructions and data move along the data bus, Memory address travel along the address bus
and control signals use the control bus.
THE CENTRAL PROCESSING UNIT (CPU):-
A central processing unit (CPU), also called a central processor or main processor, is the
electronic circuitry within a computer that executes instructions that make up a computer
program . The CPU performs basic airthmetic , logic, controlling, and input/output (I/O)
operations specified by the instructions in the program.
CPU itself has following three components.
Memory or Storage Unit
Control Unit
ALU(Arithmetic Logic Unit)
Memory or Storage Unit
This unit can store instructions, data, and intermediate results. This unit supplies information
to other units of the computer when needed. It is also known as internal storage unit or the main
memory or the primary storage or Random Access Memory (RAM).
Its size affects speed, power, and capability. Primary memory and secondary memory are two
types of memories in the computer. Functions of the memory unit are −
• It stores all the data and the instructions required for processing.
• It stores intermediate results of processing.
• It stores the final results of processing before these results are released to an output
device.
• All inputs and outputs are transmitted through the main memory.
Control Unit
This unit controls the operations of all parts of the computer but does not carry out any actual
data processing operations.
Functions of this unit are −
• It is responsible for controlling the transfer of data and instructions among other units
of a computer.
• It manages and coordinates all the units of the computer.
• It obtains the instructions from the memory, interprets them, and directs the operation
of the computer.
• It communicates with Input/Output devices for transfer of data or results from storage.
• It does not process or store data.
ALU (Arithmetic Logic Unit)
This unit consists of two subsections namely,
• Arithmetic Section
• Logic Section
Arithmetic Section
Function of logic section is to perform logic operations such as comparing, selecting, matching,
and merging of data.
Cache Memory:-
Cache Memory is a special very high-speed memory. It is used to speed up and synchronizing
with high-speed CPU. Cache memory is costlier than main memory or disk memory but
economical than CPU registers. Cache memory is an extremely fast memory type that acts as
a buffer between RAM and the CPU. It holds frequently requested data and instructions so that
they are immediately available to the CPU when needed.
Cache memory is used to reduce the average time to access data from the Main memory. The
cache is a smaller and faster memory which stores copies of the data from frequently used main
memory locations. There are various different independent caches in a CPU, which store
instructions and data.
Levels of memory:
• Level 1 or Register –
It is a type of memory in which data is stored and accepted that are immediately stored
in CPU. Most commonly used register is accumulator, Program counter, address
register etc.
• Level 2 or Cache memory –
It is the fastest memory which has faster access time where data is temporarily stored
for faster access.
• Level 3 or Main Memory –
It is memory on which computer works currently. It is small in size and once power is
off data no longer stays in this memory.
• Level 4 or Secondary Memory –
It is external memory which is not as fast as main memory but data stays permanently
in this memory.
Registers:-
Registers are a type of computer memory used to quickly accept, store, and transfer data and
instructions that are being used immediately by the CPU. The registers used by the CPU are
often termed as Processor registers.
A processor register may hold an instruction, a storage address, or any data (such as bit
sequence or individual characters).
The computer needs processor registers for manipulating data and a register for holding a
memory address. The register holding the memory location is used to calculate the address of
the next instruction after the execution of the current instruction is completed.
SECONDARY MEMORY
Secondary memory is where programs and data are kept on a long-term basis. The different
secondary memory devices are
Hard disk
Magnetic tape
CD-ROM
DVD-ROM
Blu-ray disc
Flash Memory
The obsoleted floppy disk
The Hard disk
When you save data or install programs on your computer, the information is typically written
to your hard disk. The hard disk is a spindle of magnetic disks, called platters, that record and
store information. Because the data is stored magnetically, information recorded to the hard
disk remains intact after you turn your computer off. This is an important distinction between
the hard disk and RAM, or memory, which is reset when the computer's power is turned off.
The hard disk is housed inside the hard drive, which reads and writes data to the disk. The hard
drive also transmits data back and forth between the CPU and the disk. When you save data on
your hard disk, the hard drive has to write thousands, if not millions, of ones and zeros to the
hard disk. It is an amazing process to think about, but may also be a good incentive to keep a
backup of your data.
Magnetic Tape:
Magnetic tape is a type of physical storage media for different kinds of data. It is considered
an analog solution, in contrast to more recent types of storage media, such as solid state disk
(SSD) drives. Magnetic tape has been a major vehicle for audio and binary data storage for
several decades, and is still part of data storage for some systems
Originally, magnetic tape was designed to record sound. In computing, it holds binary data. In
recent years, magnetic tape devices have become more scarce with the emergence of digital
imaging and audiovisual media storage.
Magnetic tape was used in many of the larger and less complex mainframe computers that
predated today’s personal computers (PC).
One use of magnetic tape that still exists is tape vaulting for the storage of physical records. In
this process, technicians and other professionals back up digital data to magnetic tape to secure
it in physical vaults as a redundant strategy in the event of disasters or other emergencies.
CD-ROM Stands for "Compact Disc Read-Only Memory." A CD-ROM is a CD that can be
read by a computer with an optical drive. The "ROM" part of the term means the data on the
disc is "read-only," or cannot be altered or erased. Because of this feature and their large
capacity, CD-ROMs are a great media format for retail software. The first CD-ROMs could
hold about 600 MB of data, but now they can hold up to 700 MB. CD-ROMs share the same
technology as audio CDs, but they are formatted differently, allowing them to store many types
of data.
(less than 1.44 MB for the 3.5" floppy disk) the program could be installed from one floppy
disk. However, since most programs were larger than 1.44 MB, most programs required
multiple floppy diskettes.
PORTS AND CONNECTORS :
Universal Serial Bus (USB) : The universal serial bus (USB) is so common connector which
enables us to add different types of peripherals to computers. USB is an industry-standard
connector and it can carry both data and power for example we connect our smart phones to
computer through a USB cable which enables it to transfer data as well as power to charge it.
There are different generations and speeds of USB like USB 2.0, USB 3.x and their types.
Serial Port : The serial port is a type of connection on PCs that is used for peripherals such as
mice, gaming controllers, modems, and older printers. It is sometimes called a COM port or an
RS-232 port, which is its technical name.
Parallel Port: A parallel port is an external interface commonly found on PCs from the early
1980s to early 2000s. It was used to connect peripheral devices such as printers and external
storage devices. It was eventually superseded by USB, which provides a smaller connection
and significantly faster data transfer rates.
Video Graphics Array (VGA) Port: It is the standard monitor or display interface used in
most PCs. Therefore, if a monitor is VGA-compatible, it should work with most new
computers. The VGA standard was originally developed by IBM in 1987 and allowed for a
display resolution of 640x480 pixels. Since then, many revisions of the standard have been
introduced. The most common is Super VGA (SVGA), which allows for resolutions greater
than 640x480, such as 800x600 or 1024x768. A standard VGA connection has 15 pins and is
shaped like a trapezoid.\
RJ45 Port: RJ45 is a type of connector commonly used for Ethernet networking. It looks
similar to a telephone jack, but is slightly wider. Since Ethernet cables have an RJ45 connector
on each end, Ethernet cables are sometimes also called RJ45 cables.The "RJ" in RJ45 stands
for "registered jack," since it is a standardized networking interface. The "45" simply refers to
the number of the interface standard.
PS/2 Port: The PS/2 port has six pins and is roughly circular in shape. Since each PS/2 port is
designed to accept a specific input, the keyboard and mouse connections are typically color-
coded. For example, the keyboard port on the back of the computer is often purple, while the
mouse port is usually green. Similarly, the connector on the end of the keyboard cord is purple
and the mouse cord connector is green.
High Definition Multimedia Interface (HDMI): HDMI is a trademark and brand name for a
digital interface used to transmit audio and video data in a single cable. It is supported by
modern audio/video equipment, such as 4K televisions, HDTVs, audio receivers,DVD and Blu-
Ray players, cable boxes, and video game consoles. While other types of A/V connections
require separate cables for audio and video data, a single HDMI cable carries the audio and
video streams together, eliminating cable clutter
INPUT DEVICES:
The Keyboard: A keyboard is defined as the set of typewriter-like keys that enables you to
enter data into a computer or other devices. Computer keyboards are similar to electric-
typewriters but contain additional typing keys. The standard selection of keys can be classified
as Alphanumeric keys, Punctution keys and special keys. The standard layout of letters,
numbers, and punctuation is known as QWERTY because the first six typing keys on the top
row of letters spell QWERTY. The QWERTY keyboard was designed in the 1800s for
mechanical typewriters and was actually designed to slow typists down to avoid jamming the
keys on mechanical units.
Pointing Devices: A pointing device, or sometimes called a pointing tool, is a hardware input
device that allows the user to move the mouse cursor in a computer program or GUI operating
system. Using a pointing device, you can point at or manipulate any object or text on the screen.
For example, using a pointing device you could point at and select an icon from a list of icons.
The Scanner: A scanner is an input device that scans documents such as photographs and
pages of text. When a document is scanned, it is converted into a digital format. This creates
an electronic version of the document that can be viewed and edited on a computer.
OUTPUT DEVICES:
The Monitor: A computer monitor is an output device that displays information in pictorial
form. A monitor usually comprises the visual display, circuitry, casing, and power supply.
The display device in modern monitors is typically a thin film transistor liquid crystal display
(TFT-LCD) with LED backlighting having replaced cold-cathode fluorescent lamp (CCFL)
backlighting. Older monitors used a cathode ray tube (CRT). Monitors areconnected to
the computer via VGA, Digital Visual Interface (DVI), HDMI,
DisplayPort, Thunderbolt, low-voltage differential signaling (LVDS) or other proprietary
connectors and signals.
Impact Printers: An impact printer is a type of printer that operates by striking a metal or
plastic head against an ink ribbon. The ink ribbon is pressed against the paper, marking the
page with the appropriate character , dot, line, or symbol.
Dot matrix Printer: A dot matrix printer (DMP) is a type of printer which uses pins impacting
an ink ribbon to print. These printers are generally considered outdated, as they cannot create
high-quality prints and are costly as well. they can be used to print multiple copies of text at
the same time with the help of carbon copying. Therefore, they are mostly used in places where
multipart forms are required. In a dot matrix printer, the characters and letters are formed by a
matrix of dots. A print head, which has many pins in it, moves in the required direction and
strikes against a cloth ribbon which is soaked in ink, making a mark on the paper. The dots are
spaced closely in a particular shape to make the intended character. This looks quite similar to
the printing mechanism of typewriters and daisy wheel printers. However, dot matrix printers
are different in the sense that many different characters and graphics can be printed. A character
printed by a DMP is actually an accumulation of many such dots on a small area of the paper.
Daisy Wheel Printer: A type of printer that produces letter-quality type. A daisy-wheel printer
works on the same principle as a ball-head typewriter. The daisy wheel is a disk made of plastic
or metal on which characters stand out in relief along the outer edge. To print a character, the
printer rotates the disk until the desired letter is facing the paper. Then a hammer strikes the
disk, forcing the character to hit an ink ribbon, leaving an impression of the character on the
paper. You can change the daisy wheel to print different fonts. Daisy-wheel printers cannot
print graphics , and in general they are noisy and slow, printing from 10 to about 75 characters
per second.
Line Printer: A line printer is an impact printer which makes use of a continuous feed of paper
and prints one line of text at a time. A line printer is also known as a bar printer. High speed is
one of the advantages of line printers. Compared to other printers, they are low in cost and
more durable. The consumables of line printers are less harmful to the environment and are
less costly as well. The print quality is mostly low and they cannot print graphics. Line printers
are very noisy while operating and may need soundproofing.
Non-Impact Printers: These address the drawbacks of Impact printers. The Non-impact
printers are generally much quieter than impact printers and produce documents of high
resolution.
Laser Printer: The printers laser beams your print onto a metal cylinder called a drum. Using
static electricity, the drum attracts powdered toner from its cartridge to the drum. The drum
rolls the toner onto the paper in the form of your print. The toner is melted onto the paper by
heat from a fuser as it passes underneath. Your print comes out of the printer
Inkjet Printer: At the heart of an ink jet printer are a large number of high-precision
microscopic nozzles which eject ink onto the paper. These nozzles are typically about 10
micrometers in diameter (roughly 1/10th of the diameter of a human hair). It is not unusual for
a home ink jet printer to contain thousands of nozzles in all, several hundred for each color of
ink. The diameter of each of these nozzles is fabricated with sub-micrometer accuracy to
achieve consistent and uniform ink drop volume, which is essential for consistent and uniform
color density on the page. For each color of ink, all of the nozzles on the carriage are typically
formed in a single fabrication step to precisely control their relative positions, which is
important to achieve uniform print without banding. In some cases, all of the nozzles for every
color of ink are formed together in a single step. The nozzles are all formed as orifices through
a single planar sheet of a material. This material is selected for its compatibility with the
particular fabrication method chosen. The ink jet nozzles are all mounted together on a moving
carriage assembly that moves at high velocity (typically > 1 meter per second) back and forth
across the paper. The nozzles are mounted about 1 mm from the paper, and ink ejection
velocities are in the range of 5 to 10 meters per second. Ink is ejected from a nozzle by applying
a pulse of pressure to the fluid ink in the supply tube, upstream of that nozzle
Plotters: A plotter is a printer designed for printing vector graphics. Instead of printing
individual dots on the paper, plotters draw continuous lines. This makes plotters ideal for
printing architectural blueprints, engineering designs, and other CAD drawings. There are two
main types of plotters – drum and flatbed plotters. Drum plotters (also called roller plotters)
spin the paper back and forth on a cylindrical drum while the ink pens move left and right. By
combining these two directions, lines can be drawn in any direction. Flatbed plotters have a
large horizontal surface on which the paper is placed. A traveling bar draws lines on the paper
as it moves across the surface.
Most drum and flatbed plotters provide output sizes that are much larger than standardinkjet
and laser printer. The length of a document printed by a drum plotter is only limited by the size
of the paper. Documents printed by flatbed plotters are constrained to the length and width of
the printing surface.
Network Topology: Network topology refers to the physical or logical layout of a network. It
defines the way different nodes are placed and interconnected with each other. Alternately,
network topology may describe how the data is transferred between these nodes.
Star Topology: A star topology is a topology for a Local Area Network (LAN) in which all
nodes are individually connected to a central connection point, like a hub or a switch.
Star Topology
Token Ring topology: A ring network is a network topology in which each node connects to
exactly two other nodes, forming a single continuous pathway for signals through each node in
a ring. Data travels from node to node, with each node along the way handling every packet.
Ring Topology
• Mesh topology: A network setup where each computer and network device is interconnected
with one another, allowing for most transmissions to be distributed even if one of the
connections go down. It is a topology commonly used for wireless networks.
MeshTopology
Bus topology: A bus topology is a topology for a Local Area Network (LAN) in which all the
nodes are connected to a single cable. The cable to which the nodes connect is called a
"backbone". If the backbone is broken, the entire segment fails.
Bus Topology
Switch is a network device which is used to enable the connection establishment and
connection termination on the basis of need. Switch is operated on Data link layer. In this
packet filtering is available. It is type of full duplex transmission mode and it is also called
efficient bridge.
Bridge and Router: Bridge is a network device, which works in data link layer. Through
bridge, data or information is store and sent in the form of packet. Whereas Router is also a
network device which works in network layer. Through router, data or information is store and
sent in the form of packet.
SOFTWARE BASICS:
Software, instructions that tell a computer what to do. Software comprises the entire set of
programs, procedures, and routines associated with the operation of a computer system. The
term was coined to differentiate these instructions from hardware—i.e., the physical
components of a computer system. A set of instructions that directs a computer’s hardware to
perform a task is called a program, or software program.
Software is broadly classified into two types
1. System Software
2. Application Software
System Software: System software refers to the files and programs that make up your
computer's operating system. System files include libraries of functions, system services,
drivers for printers and other hardware, system preferences, and other configuration files. The
programs that are part of the system software include assemblers, compilers, file management
tools, system utilities, and debuggers.
Types of System Software:
Example:
1. Design an algorithm and flowchart to find sum of two numbers
Algorithm:- Flowchart:-
Step 1: Start
Step 2: Read a,b
Step 3: sum←a+b
Step 4 : Print “sum”
Step 5: Stop
Example:
2. Design an algorithm and flowchart to find area and circumference of circle
Algorithm:- Flowchart:-
Step 1: Start
Step 2: Read r
Step 3: area←3.142*r*r
Step 4: circum←2*3.142*r
Step 5: Print “area,circum”
sStep 6: Stop
Example:
3. Design an algorithm and flowchart to compute simple interest
Algorithm:- Flowchart:-
Step 1: Start
Step 2: Read p,t,r
Step 3: si←(p*t*r)/100
Step 4 : Print “si”
Step 5: Stop
HISTORY OF C
C is a general purpose, procedural, structured computer programming language developed by
Dennis Ritchie in the year 1972 at AT&T Bell Labs.
C language was developed on UNIX and was invented to write UNIX system software.
C is a successor of B language.
There are different C standards: K&R C std, ANSI C, ISO 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
C Character Set:
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, carriage return, new line character, form
feed character.
Basic structure of C Program
Every c program is made up of one or more pre-processor commands, global declarations, and
one or more functions.
Documentation section :consists of a set of comment line giving the name of the program, the
author, and other details. Compiler ignores these comments when it translates the program into
executable code. C uses 2 different formats
1. Block comments /*this is multi line comments*/
2. Line comments //this is single line comments
The Link section: provides instruction to the compiler to link functions from system library.
This Section is also called as pre-processor Statements.
Global Declaration section: there are some variables that are used in more than on function,
such a variable are called global variable and are declared in the global declaration section that
is outside of all functions. This section also defines user defined functions.
Every C program must have one main () function section. This section contains two parts
declaration part and executable part
Declaration part declares all the variables used in the executable part
There is at least one statement in an executable part. These two part must appear at the
beginning of the brace and ends at the closing brace. All statement in the declaration and
executable part ends with semicolon (;).
The sub program section: contains all the user defined functions that are called in the main
function although they appear in any order.
Here is a small program that displays a sentence “Welcome to C Programming for Problem
solving” on the monitor screen:
/* C program to display a welcome message */
#include<stdio.h>
void main( )
{
printf(“Welcome to C Programming for Problem solving”);
}
C Tokens: In C program the smallest logically meaning full individual units are known as c
tokens. These are also called as the basic building blocks of C program which cannot be further
broken into subparts. C has 6 Different types of tokens. C programs are written using these
tokens and syntax of the language.
i. Keywords
ii. Identifiers
iii. Constants
iv. Strings
v. Operators
vi. Special symbols
1. Keywords: These are predefined words in C compiler which are ment for specific purpose.
These words are also called as reserved words. These words cannot be used as variable names.
These words are usually case sensitive and are usually written in lower case letters only. There
are 32 keywords in C.
2. Identifiers: These are the names given to various elements of the C program like variables,
functions, arrays, etc. These are user defined names and consist of sequence letters, digits or
underscore.
Rules to define an Identifiers
1. The first character of the identifier must always be a letter or an underscore followed by any
number of letters digits or underscore.
2. Keywords cannot be used as identifiers or variables.
3. An Identifier or a variable should not contain two consecutive underscores
4. Whitespaces and special symbols cannot be used to name the identifiers.
5. Identifiers are case sensitive (A same variable name declared in uppercase letters and lower
case letters are two different variables in C program).
Examples
food_court valid identifier
$num Invalid identifier ($ is a special symbol)
3. Constants: These are the fixed values assigned to the variables which cannot be cannot be
changed or modified in the program. Constants are broadly classified as
Numeric Constants:
Integer Constant: These contain digits or whole numbers without decimal point which can be
either positive or negative.
(i) Decimal: It is an integer constant consisting of numbers from 0-9. It can be preceded by + or –
(ii) Octal: It is an integer constant consisting of numbers from 0-7. It is preceded by o
(iii) 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: These contain an decimal point or an exponent or both. It can be either positive
or negative or both.
Example: 21.5, 3.142, 6.6260X10-34 , 2.15X102 → 2.15e2
Character Constants:
Single Character Constant: can be single character enclosed within single quotes or a ‘\’
(backslash) followed by any character. ‘\’ is called escape character as it alters the meaning of
character following it. Following are the complete list of escape sequence.
String Constant: String constants also termed as string literal are sequences of characters
enclosed in double quotes. The character may be letters, numbers, special characters and blank
space. a String literal always ends with a Null character (‘\0’)
Example:
M I T E ‘\0’
5. Operators: An operator is a symbol that tells the compiler to perform specific mathematical
and logical functions. The different operators supported in ‘C’ are:
(i) Arithmetic Operators
(ii) Relational Operators
(iii) Logical Operators
(iv) Assignment Operators
(v) Bitwise Operators
(vi) Unary Operators→ Increment and Decrement
(vii) Ternary/ Conditional Operator
(viii) Special Operators
(i) Arithmetic Operators: These operators are used to perform basic arithmetic operations
Operator Name Result Syntax Example (b=5, c=2)
+ Addition Sum a=b+c a=7
- Subtraction Difference a=b-c a=3
* Multiplication Product a=b*c a = 10
/ Division Quotient a=b/c a=2
% Modulus Remainder a=b%c a=1
(ii) Relational Operators: This operator compares two operands inorder to find out the
relation between them. The output will be either 0 (False) or 1 (True).
(iii) Logical Operators: These are used to test more than one condition and make decision.
The different logical operators are:
❖ Logical NOT
❖ Logical AND
❖ Logical 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
(iv) Assignment Operators: The assignment operator is used to assign the values to the
variables on the left hand side. The symbol “=” is used as an assignment operator.
Example: x = 10, c = a+b
Shorthand Assignment: An expression can be written in a compact manner i.e. if the operand
on the left hand side of the assignment operator is same as the first operand of the right hand
side expression it can be written using the shorthand assignment operator
Example: x = x+2 → x+=2
Multiple Assignment: If more than one variable holds the same value we can use multiple
assignment to avoid rewriting of the same values repeatedly.
Example: a=10,b=10,c=10 → a=b=c=10
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
I. Primary or built-in or primitive data type: These are the data types which are already
predefined by the compiler.
(i) Integer data type: It is used to store whole numbers and its range depends on the word
length defined for a computer. It usually occupies 2 bytes of memory, for signed integers the
value ranges from -2n-1 to +2n-1-1 and for unsigned integers the value ranges from 0 to 2n-1.
Keyword int is used to declare variables of integer data type.
(ii) Floating point data type: It is used to store decimal numbers that have single precision
floating point value. It provides 6 digits after the decimal point and occupies 4 bytes of memory.
Keyword float is used to declare variables of floating point data type.
(iii) Double data type: These are used to store real numbers that have double precision floating
point value. It provides 16 digits after the decimal point. this data type is used when performing
complex calculations to get accurate results. It occupies 8 bytes of memory. Keyword double
is used to store the variables of double data type.
(iv) Char data type: This data type basically stores character type of data. the character data
can be an Alphabet [a to z or A to Z] , digits [0 to 9] and all special characters or
symbols[@,$,&,#,...]which is enclosed with in single quotes. It occupies one byte of memory.
Keyword char is used to declare variables of character data type.
(v) Void data type: It does not store any value hence we cannot store any operation on the
variable declared as void. It has no range. Keyword void is used to specify non return data type.
II. Derived data type: These are the data types which are derived from the primitive data
types. There are mainly three derived data types
(i) Arrays: Sequence of data items having homogeneous values.
(iii) Pointers: These are used to access the memory and deal with their addresses
III. User defined data type: The type definition feature of C allows the user to define an
identifier which acts as data type using an existing basic data type. Such identifier is called as
user defined data types.
(i) Structure: It is a package of variable of different types under a single name. struct keyword
is used to define a structure.
(ii) UNION: This allows storing various data types in the same memory locations.
(iii) ENUM: Enumeration is a special data type that consists of integral constants and each of
them is assigned with a specific name. enum keyword is used to create the enumerated data
type.
Data type Modifiers: Built in data types except void data type can easily be modified by using
data type modifier. There are mainly 4 data type modifiers:
(i) Signed (ii) Unsigned (iii) Long (iv) Short
(i) Signed: it indicates that the variable is capable of storing the negative numbers. The values
will be in this range. -2n-1 to +2n-1-1. Where, n is the size of the particular data type in bits. In
declaration we have to use signed keyword. Example: signed int a;
(ii) Unsigned: it indicates that the variable is capable of storing only positive numbers The
values will be in this range. 0 to 2n-1. Where, n is the size of the particular data type in bits. In
declaration we have to use unsigned keyword. Example: unsigned int a;
(iii) Long: It is used to increase the storage capacity of the variable. long keyword can be used
as shown long int a; //long int occupies 4 bytes of memory.
(iv) Short: It is used to decrease the storage capacity of the variable (capacity is reduced to
half). short keyword can be used as shown short int a; //short int occupies 1 bytes of memory.
Format Specifiers: These are used to tell the compiler about the type of data being used
Data Type Format Specifier Meaning
%d Decimal integer
%o Octal integer
%x Hexadecimal integer
Integer (int)
%i Decimal, hex or octal int
%u Unsigned integer
%h Short integer
Floating Point %e
floating point
(float) %f
%g
%c Single character
Character (char)
%s String data
Double (double) %lf Floating point number or double
Long Integer %ld long integer value
Type Conversion: It is a process of converting an expression from one data type to another
data type
There are two types:
Implicit Type conversion
Explicit Type Conversion
Implicit Type Conversion: This type of conversion is done by the compiler, so it is called as
implicit type conversion. Without user intervention this process is carried out. Whenever we
are converting narrow operand (lower data type variable) into wide operand (higher data type
variable) then compiler will do it implicitly.
Example:
#include<stdio.h>
void main( )
{
char b= ‘A’;
int a;
a=b;
printf(“%d”,a);
}
OUTPUT: 65
Explicit Type Conversion: This type of conversion is done by the user so it is called explicit
type conversion. Whenever we are converting wider operand (higher data type variable) into a
narrower operand (lower data type variable) then its called explicit conversion.
Example:
#include<stdio.h>
void main()
{
int a=4;
float b;
b=1/(float)a;
printf(“%f”,b);
}
OUTPUT: 0.250000
=
*= /= %=
+= -= &= Assignment operators Right to left 14
^= |=
<<= >>=
, Comma operator Left to right 15
Examples:
1. If a=8, b=15 and c=4 calculate the expression
2*((a%5)*(4+(b–3)/(c+2)))
= 2 * ( ( 8 % 5 ) * ( 4 + ( 15 – 3 ) / ( 4 + 2 ) ) ) //Substitution of values
= 36 //Final Result
→ 5 <= 10 – 5 + 0 – 20 == 5 >= 1 != 20
→ 5 <= 5 + 0 – 20 == 5 >= 1 != 20
→ 5 <= 5 – 20 == 5 >= 1 != 20
→ 0 == 1 != 20
→ 0 != 20
→1
√𝑣 → sqrt(v)
| h | → abs(h)
gt → pow(g,t)
ex → exp(x)
sin x → sin (x)
sin 45o → sin ( ( 45 * 3.142 ) / 180) /*converting degrees to radians*/
𝑒√𝑥+𝑒√𝑦
3. 𝑃 = → P = ( exp ( sqrt ( x ) ) + exp ( sqrt ( y ) ) ) / ( x * sin ( sqrt ( y ) )
𝑥𝑠𝑖𝑛√𝑦
−𝑏+√𝑏2−4𝑎𝑐
4. 𝑋 = → X= ( ( -b ) + sqrt ( b * b – 4 * a * c ) ) / ( 2 * a )
2𝑎