0% found this document useful (0 votes)
54 views42 pages

IP Unit-1-1

Uploaded by

maneeshgopisetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views42 pages

IP Unit-1-1

Uploaded by

maneeshgopisetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Introduction to Programming I-B.

Tech, I-Semester
UNIT-1
Q1)Explain the History of Computers?
The first counting device was used by the primitive people. They used sticks, stones and bones
as counting tools. As human mind and technology improved with time more computing devices
were developed. Some of the popular computing devices starting with the first to recent ones
are described below:
Abacus: The history of computer begins with the birth of abacus which is
believed to be the first computer. It is said that Chinese invented Abacus
around 4,000 years ago.
It was a wooden rack which has metal rods with beads mounted on them.
The beads were moved by the abacus operator according to some rules to
perform arithmetic calculations. Abacus is still used in some countries like
China, Russia and Japan. An image of this tool is shown beside:
Napier's Bones: It was a manually-operated calculating device which was
invented by John Napier (1550-1617) of Merchiston. In this calculating tool, he
used 9 different ivory strips or bones marked with numbers to multiply and
divide. So, the tool became known as "Napier's Bones. It was also the first
machine to use the decimal point.
Pascaline: Pascaline is also known as Arithmetic Machine or Adding
Machine. It was invented between 1642 and 1644 by a French mathematician-
philosopher Biaise Pascal. It is believed that it was the first mechanical and
automatic calculator. Pascal invented this machine to help his father, a tax
accountant. It could only perform addition and subtraction. It was a wooden
box with a series of gears and wheels. When a wheel is rotated one
revolution, it rotates the neighboring wheel. A series of windows is given on the top of the
wheels to read the totals. An image of this tool is shown beside:
Stepped Reckoner or Leibnitz wheel: It was developed by a German
mathematician-philosopher Gottfried Wilhelm Leibnitz in 1673. He improved
Pascal's invention to develop this machine. It was a digital mechanical calculator
which was called the stepped reckoner as instead of gears it was made of fluted
drums. See the following image:
Difference Engine: In the early 1820s, it was designed by Charles Babbage
who is known as "Father of Modern Computer". It was a mechanical computer
which could perform simple calculations. It was a steam driven calculating
machine designed to solve tables of numbers like logarithm tables.

Analytical Engine: This calculating machine was also developed by Charles


Babbage in 1830. It was a mechanical computer that used punch-cards as input. It
was capable of solving any mathematical problem and storing information as a
permanent memory.
Tabulating Machine: It was invented in 1890, by Herman Hollerith, an
American statistician. It was a mechanical tabulator based on punch cards. It
could tabulate statistics and record or sort data or information. This machine
was used in the 1890 U.S. Census. Hollerith also started the Hollerith?s
Tabulating Machine Company which later became International Business
Machine (IBM) in 1924.
Differential Analyzer: It was the first electronic computer introduced in
the United States in 1930. It was an analog device invented by Vannevar Bush.
This machine has vacuum tubes to switch electrical signals to perform
calculations. It could do 25 calculations in few minutes.

P.Madhubabu M.C.A & M.Tech 1


Introduction to Programming I-B.Tech, I-Semester
Mark I: The next major changes in the history of computer began in 1937
when Howard Aiken planned to develop a machine that could perform
calculations involving large numbers. In 1944, Mark I computer was built as a
partnership between IBM and Harvard. It was the first programmable digital
computer.

Q2)What are Generation of Computers?


Generation means enhancement (extension, expansion) in technology such as speed, size
and Memory capacity. Based upon this the computer generations are classified into 5 types.
1)First Generation (1940-1956: Vacuum Tubes):
i) vacuum tubes are used in electronic circuits
ii) Mercury Delay lines are used as memory
iii) Magnetic drums are used as secondary memory
iv) Machine level language is used as programming
v) The size of computer is very large
vi) The maintenance is very difficult because it produces large amount of heat. So AC is
compulsory
vii) Punched card are used to enter the data into the computer, punched card was a sheet of
thick paper, in which holes were punched according to a coding scheme.
2)Second Generation (1956-1963: Transistors)
i) Transistors were used
ii) Magnetic tapes are used as Secondary Memory
iii) Magnetic disks are used as primary memory
iv) High Level language is used as the programming
Ex: Fortran, cobol etc..
v) The size of computer is reduced
vi) Input, output operations made faster
vii) The maintenance of computer is reduced because the heat was reduced
viii) These are used for both commercial and Scientific applications
ix) Batch processing is possible
3)Third Generation (1964-1971: Integrated Circuits):
i) IC’s are used in electronic circuits
ii) Memory capacity is increased upto Mega Bytes.
iii) The size of computer is small
iv) Magnetic disks are used as secondary memory
v) IC’s are used as Main Memory
vi)The processing speed is very high. It can process 10 million instructions per second.
vii) These are used for scientific and commercial applications
viii) Instead of punched cards and printouts, users interacted with third generation
computers through keyboards and monitors and interfaced with an operating system,
which allowed the device to run many different applications.
ix)simple input and output operations
4)Fourth Generation (1971-Present: Microprocessors):
i)The microprocessor brought the fourth generation of computers, as
thousands of integrated circuits were built onto a single silicon chip.
ii)Very Large Scale Integrated Circuits(VLSIC) were used
iii)The speed of the computer is very high
iv)It required less space, not necessary AC
5)Fifth Generation (Present and Beyond: Artificial Intelligence):
Fifth generation computing devices, based in Artificial intelligence, are still in development,
though there are some applications, such as voice recognition, that are being used today.

P.Madhubabu M.C.A & M.Tech 2


Introduction to Programming I-B.Tech, I-Semester
Artificial Intelligence is the branch of computer science concerned with making computers
behave like humans. Artificial intelligence includes:
 Games Playing: programming computers to play games such as chess and checkers
 Expert Systems: programming computers to make decisions in real-life situations (for
example, some expert systems help doctors diagnose diseases based on symptoms)
 Natural Language: programming computers to understand natural human languages.

Q3)Explain Basic Organization of Computer?


(or)
Explain various parts of the computer?
(or)
Explain Logical Organization of the Digital computer?
(or)
Explain Block diagram of the computer?
(or)
Explain various components of a digital computer?
Computer: Computer is an Electronic Device that takes the data as input from the user, stores
that data and process the data and generates the output as per the instructions given by the
user.
Just like the other machines, the computer has also a basic architecture. It comprises multiple
elements. These elements process the input and produce the desired output.
Let us look at the basic block diagram of the computer. Then, we will understand how each part
contributes to its functioning.
The computer system mainly divided into three units
1)Input Unit
2)Central Processing Unit
3)Output Unit
It can be diagrammatically represented as follows:

1)Input Unit: All the data received by the computer goes through the input unit. The input
unit comprises different devices. Like a mouse, keyboard, scanner, etc. In other words, each of
these devices acts as a mediator between the users and the computer.
The data that is to be processed is put through the input unit. The computer accepts the raw
data in binary form. It then processes the data, and produces the desired output.
The 3 major functions of the input unit are-

P.Madhubabu M.C.A & M.Tech 3


Introduction to Programming I-B.Tech, I-Semester
 Take the data to be processed by the user.
 Convert the given data into machine-readable form.
 And then, transmit the converted data into the main memory of the computer. The sole
purpose is to connect the user and the computer. In addition, this creates easy
communication between them.
2)Central Processing Unit(CPU): Central Processing Unit or the CPU, is the brain of the
computer. It works the same way a human brain works. As the brain controls all human
activities, the CPU too controls all tasks.
Moreover, the CPU conducts all the arithmetical and logical operations in the computer.
This is again divided into three units.
a) Control Unit
b) Arithmetic Logic Unit
c) Memory Unit
a)Control Unit: The Control Unit is used to control all the other parts of the computer. For
example the input unit does not know when to send the data when the output unit receives the
data. The Control Unit gives direction to the other units. It gives the instructions to the data
from the input device to memory, from memory to ALU and ALU to Output device.
b)Arithmetic Logic Unit (ALU): ALU is used to perform all arithmetic(+, - ,* ,/ ,%) and
logical (and, or, not) operations. The input data in the form of binary numbers will be transfer
to ALU, whenever the processing is necessary.
c)Memory Unit: The computer Memory is used to store many types of information. The
memory locations are called memory cells. Each memory cell is capable of storing one character
also known as a byte. Byte is the combination of 8 bits. Bit is either 0 or 1.
The memory can be measured in terms of bits and bytes.
Nibble = 4bits
1 byte = 8 bits
1 kb = 1024 bytes
1 mb = 1024 kbs
1 gb = 1024 mbs
1 tb = 1024 gb
Memory is classified into 2 types:
i)Main Memory/primary memory
ii)Secondary Memory
i)Primary memory: This type of memory cannot store a vast amount of data. Therefore, it is
only used to store recent data. The data stored in this is temporary. It can get erased once the
power is switched off. Therefore, is also called temporary memory or the main memory.
RAM stands for Random Access Memory. It is an example of primary memory. This memory is
directly accessible by the CPU. It is used for reading and writing purposes. For data to be
processed, it has to be first transferred to the RAM and then to the CPU.
ii)Secondary memory: For permanent storage purposes, secondary memory is used. It is also
called the permanent memory or the auxiliary memory. The hard disk is an example of
secondary memory. Even in a power failure data does not get erased easily.
3)Output Unit: All the information sent to the computer once processed is received by the
user through the output unit. Devices like printers, monitors, projector, etc. all come under the
output unit.
The output unit displays the data either in the form of a soft copy or hard copy. The printer is
for the hard copy. The monitor is for the display. The output unit accepts the data in binary
form from the computer. It then converts it into a readable form for the user.
The most commonly used output devices are:
1)Visual Display Unit(Monitor)
2)Printer
3)Plotter

P.Madhubabu M.C.A & M.Tech 4


Introduction to Programming I-B.Tech, I-Semester
Q4)What is computer? Explain characteristics and limitations of a
computer?
Computer: Computer is an Electronic Device that takes the data as input from the user, stores
that data and process the data and generates the output as per the instructions given by the
user.
Characteristics of Computer:
1) Accuracy
2) Speed
3) Versatility (Flexibility, usefulness)
4) Storage capability
5) Intellectual power (logical)
6) Diligence
7) Network capacity
1)Accuracy: Computer system always produces correct results. It cannot never do mistake.
Then the user given data is wrong then only it gives wrong results. The accuracy of a particular
computer depends upon the system design.
2)Speed: Computer can process millions of instructions per second. Even complex problems
also processed in fraction of seconds. The speed of the computer is measured in terms of Micro
seconds(10-6), Nano seconds(10-9) and Pico seconds(10-12).
3)Versatility: Versatility means it can do number of jobs at a time.
Example: In computer we can draw the picture on one side other side we can print the
documents.
4)Storage capability: The main purpose of the computer is storing of the data. The
computer can store large amount of data and information ones we store the data we can
retrieve the data any time. The storage capacity of computer can be increased by using
secondary storage devices such as magnetic discs, tapes etc.. The memory can be measured in
terms of bits and bytes.
Nibble = 4bits
1 byte = 8 bits
1 kb = 1024 bytes
1 mb = 1024 kbs
1 gb = 1024 mbs
1 tb = 1024 gb
5)Intellectual Power: A computer doesn’t take its own decision. Now a day some Artificial
Intelligence Technology has been developed. So that computer takes its own decision.
6)Diligence: Diligence means being constant in effort. Human being suffers from weakness
and tiredness lack of concentration. Computer machine don’t suffer and can work for hours and
perform limitless calculation without time limit.
7)Network Capacity: Computers can communicate with other computers and can receive
and send data in various forms like Text, video, audio and graphics. Per this computer network
internet is developed.
Limitations of a computer: Although a computer is far better in performance than a
human being, it fails in certain ways as follows:
i)computers can’t think: computers can not think and they can’t do any job unless they are
first programmed with specific instructions for same. They work as per stored instructions.
Algorithms are designed by humans to make a computer perform a special task. This is also
called artificial intelligence.
ii)Computers can’t Decide: computers are incapable of decision making as they do not
possess the essential elements necessary to take a decision. i.e. knowledge, information,
wisdom, intelligence and the ability to judge.

P.Madhubabu M.C.A & M.Tech 5


Introduction to Programming I-B.Tech, I-Semester
iii)computers can’t Express their Ideas: In any type of research ideas plays a vital role. In
this context, computers can’t express their ideas.
iv)computers can’t implement: Though computers are helpful in storage of data and can
contain the contents of encyclopedias even, but only human can decide and implement the
policies.

Q5)What are the Applications of Computers? (or) What are the uses of
Computers?
Computers play a role in every field of life. They are used in homes, business, educational
institutions, research organizations, medical field, government offices, entertainment, etc.
1.Home: Computers are used at homes for several purposes like online bill payment,
watching movies or shows at home, home tutoring, social media access, playing games, internet
access, etc. They provide communication through electronic mail. They help to avail work from
home facility for corporate employees. Computers help the student community to avail online
educational support.
2.Medical Field: Computers are used in hospitals to maintain a database of patients’
history, diagnosis, X-rays, live monitoring of patients, etc. Surgeons nowadays use robotic
surgical devices to perform delicate operations, and conduct surgeries remotely. Virtual reality
technologies are also used for training purposes. It also helps to monitor the fetus inside the
mother’s womb.
3.Entertainment: Computers help to watch movies online, play games online; act as a
virtual entertainer in playing games, listening to music, etc. MIDI instruments greatly help
people in the entertainment industry in recording music with artificial instruments. Videos can
be fed from computers to full screen televisions. Photo editors are available with fabulous
features.
4.Industry: Computers are used to perform several tasks in industries like managing
inventory, designing purpose, creating virtual sample products, interior designing, video
conferencing, etc. Online marketing has seen a great revolution in its ability to sell various
products to inaccessible corners like interior or rural areas. Stock markets have seen phenomenal
participation from different levels of people through the use of computers.
5.Education: Computers are used in education sector through online classes, online
examinations, referring e-books, online tutoring, etc. They help in increased use of audio-visual
aids in the education field.
6.Government: In government sectors, computers are used in data processing, maintaining
a database of citizens and supporting a paperless environment. The country’s defense
organizations have greatly benefitted from computers in their use for missile development,
satellites, rocket launches, etc.
7.Banking: In the banking sector, computers are used to store details of customers and
conduct transactions, such as withdrawal and deposit of money through ATMs. Banks have
reduced manual errors and expenses to a great extent through extensive use of computers.
8.Business: Nowadays, computers are totally integrated into business. The main objective of
business is transaction processing, which involves transactions with suppliers, employees or
customers. Computers can make these transactions easy and accurate. People can analyze
investments, sales, expenses, markets and other aspects of business using computers.
9.Training: Many organizations use computer-based training to train their employees, to
save money and improve performance. Video conferencing through computers allows saving of
time and travelling costs by being able to connect people in various locations.
10.Arts: Computers are extensively used in dance, photography, arts and culture. The fluid
movement of dance can be shown live via animation. Photos can be digitized using computers.

P.Madhubabu M.C.A & M.Tech 6


Introduction to Programming I-B.Tech, I-Semester
11.Science and Engineering: Computers with high performance are used to stimulate
dynamic process in Science and Engineering. Supercomputers have numerous applications in
area of Research and Development (R&D). Topographic images can be created through
computers. Scientists use computers to plot and analyze data to have a better understanding of
earthquakes.

Q6)Explain various types of Input devices?


Following are few of the important input devices which are used in a computer:
1. Keyboard
2. Mouse
3. Joy Stick
4. Light pen
5. Track Ball
6. Scanner
7. Graphic Tablet
8. Microphone
9. Magnetic Ink Card Reader(MICR)
10. Optical Character Reader(OCR)
11. Bar Code Reader
12. Optical Mark Reader(OMR)
1.Keyboard: Keyboard is the most common and very popular
input device which helps in inputting data to the computer. The
layout of the keyboard is like that of traditional typewriter,
although there are some additional keys provided for performing
additional functions.
Keyboards are of two sizes 84 keys or 101/102 keys, but now
keyboards with 104 keys or 108 keys are also available for
Windows and Internet.
The keys on the keyboard are as follows:

2.Mouse: Mouse is most popular pointing device. It is a very


famous cursor-control device having a small palm size box with a
round ball at its base which senses the movement of mouse and sends
corresponding signals to CPU when the mouse buttons are pressed.
Generally it has two buttons called left and right button and a wheel
is present between the buttons. Mouse can be used to control the position of cursor on screen,
but it cannot be used to enter text into the computer.

3.Joystick: Joystick is also a pointing device which is used to move cursor


position on a monitor screen. It is a stick having a spherical ball at its both lower
and upper ends. The lower spherical ball moves in a socket. The joystick can be
moved in all four directions.
The function of joystick is similar to that of a mouse. It is mainly used in
Computer Aided
Designing(CAD) and playing computer games.

4.Light Pen: Light pen is a pointing device which is similar to a pen. It


is used to select a displayed menu item or draw pictures on the monitor
screen. It consists of a photocell and an optical system placed in a small
tube. When the tip of a light pen is moved over the monitor screen and
pen button is pressed, its photocell sensing element detects the screen
location and sends the corresponding signal to the CPU.

P.Madhubabu M.C.A & M.Tech 7


Introduction to Programming I-B.Tech, I-Semester
5.Track Ball: Track ball is an input device that is mostly used in
notebook or laptop computer, instead of a mouse. This is a ball which is
half inserted and by moving fingers on ball, pointer can be moved. Since
the whole device is not moved, a track ball requires less space than a
mouse. A track ball comes in various shapes like a ball, a button and a
square.

6.Scanner: Scanner is an input device which works more like a photocopy


machine. It is used when some information is available on a paper and it is to
be transferred to the hard disc of the computer for further manipulation.
Scanner captures images from the source which are then converted into the
digital form that can be stored on the disc. These images can be edited before
they are printed.

7.Digitizer: Digitizer is an input device which converts analog


information into digital form. Digitizer can convert a signal from the
television or camera into a series of numbers that could be stored in a
computer. They can be used by the computer to create a picture of
whatever the camera had been pointed at. Digitizer is also known as
Tablet or Graphics Tablet because it converts graphics and pictorial data
into binary inputs. A graphic tablet as digitizer is used for doing fine works of drawing and
image manipulation applications.

8.Microphone: Microphone is an input device to input sound that is then


stored in digital form. The microphone is used for various applications like
adding sound to a multimedia presentation or for mixing music.

9.Magnetic Ink Card Reader(MICR): MICR input device is


generally used in banks because of a large number of cheques to be
processed every day. The bank's code number and cheque number are
printed on the cheques with a special type of ink that contains particles of
magnetic material that are machine readable. This reading process is called
Magnetic Ink Character Recognition (MICR). The main advantages of MICR
is that it is fast and less error prone.

10.Optical Character Reader(OCR): OCR is an input device used to


read a printed text. OCR scans text optically character by character, converts
them into a machine readable code and stores the text on the system
memory.

11.Bar Code Readers: Bar Code Reader is a device used for reading
bar coded data (data in form of light and dark lines). Bar coded data is
generally used in labelling goods, numbering the books etc. It may be a
hand held scanner or may be embedded in a stationary scanner. Bar Code
Reader scans a bar code image, converts it into an alphanumeric value
which is then fed to the computer to which bar code reader is connected.

12.Optical Mark Reader(OMR): OMR is a special type of


optical scanner used to recognize the type of mark made by pen or
pencil. It is used where one out of a few alternatives is to be selected
and marked. It is specially used for checking the answer sheets of
examinations having multiple choice questions.
P.Madhubabu M.C.A & M.Tech 8
Introduction to Programming I-B.Tech, I-Semester
Q7)Explain various types of Output devices?
Following are few of the important output devices which are used in a computer.
1. Monitors
2. Printer
3. Graphic Plotter
1.Monitors: Monitors, commonly called as Visual Display Unit (VDU), are the main output
device of a computer. It forms images from tiny dots, called pixels that are arranged in a
rectangular form. The sharpness of the image depends upon the number of pixels.
There are two kinds of viewing screen used for monitors.
a) Cathode-Ray Tube (CRT)
b) Flat- Panel Display
a)Cathode-Ray Tube (CRT) Monitor: The CRT display is made
up of small picture elements called pixels. The smaller the pixels, the
better the image clarity, or resolution. It takes more than one
illuminated pixel to form whole character, such as the letter ‘e’ in the
word help.
A finite number of characters can be displayed on a screen at once.
The screen can be divided into a series of character boxes - fixed
location on the screen where a standard character can be placed. Most screens are capable of
displaying 80 characters of data horizontally and 25 lines vertically. There are some
disadvantages of CRT:
 Large in Size
 High power consumption

b)Flat-Panel Display Monitor: The flat-panel display refers to a


class of video devices that have reduced volume, weight and power
requirement in comparison to the CRT. You can hang them on walls
or wear them on your wrists. Current uses of flat-panel displays
include calculators, video games, monitors, laptop computer, graphics
display.
The flat-panel display is divided into two categories:
 Emissive Displays - The emissive displays are devices that convert electrical energy into
light. Example are plasma panel and LED(Light-Emitting Diodes).
 Non-Emissive Displays - The Non-emissive displays use optical effects to convert
sunlight or light from some other source into graphics patterns. Example is LCD(Liquid-
Crystal Device)

2.Printers: Printer is an output device, which is used to print information on paper.


There are two types of printers:
i)Impact Printers
ii)Non-Impact Printers
i)Impact Printers: The impact printers print the characters by striking them on the ribbon
which is then pressed on the paper.
Characteristics of Impact Printers are the following:
 Very low consumable costs
 Very noisy
 Useful for bulk printing due to low cost
 There is physical contact with the paper to produce an image
These printers are of two types
a) Character printers
b) Line printers
a)Character Printers: Character printers are the printers which print one character at a time.
P.Madhubabu M.C.A & M.Tech 9
Introduction to Programming I-B.Tech, I-Semester
These are further divided into two types:
 Dot Matrix Printer(DMP)
 Daisy Wheel
Dot Matrix Printer: In the market one of the most popular printers is Dot Matrix Printer.
These printers are popular because of their ease of printing and economical price. Each character
printed is in form of pattern of dots and head consists of a Matrix of Pins of size (5*7, 7*9, 9*7
or 9*9) which come out to form a character that is why it is called Dot Matrix Printer.
Advantages:
 Inexpensive
 Widely Used
 Other language characters can be printed
Disadvantages:
 Slow Speed
 Poor Quality

Daisy Wheel: Head is lying on a wheel and pins corresponding to characters are like petals of
Daisy (flower name) that is why it is called Daisy Wheel Printer. These printers are generally
used for word-processing in offices which require a few letters to be sent here and there with
very nice quality.
Advantages:
 More reliable than DMP
 Better quality
 The fonts of character can be easily changed
Disadvantages:
 Slower than DMP
 Noisy
 More expensive than DMP

b)Line Printers: Line printers are the printers which print one line at a time.
These are of further two types
i)Drum Printer
ii)Chain Printer
i)Drum Printer: This printer is like a drum in shape so it is called drum
printer. The surface of drum is divided into number of tracks. Total tracks are equal to size of
paper i.e. for a paper width of 132 characters, drum will have 132 tracks. A character set is
embossed on track. The different character sets available in the market are 48 character set, 64
and 96 characters set. One rotation of drum prints one line. Drum printers are fast in speed and
can print 300 to 2000 lines per minute.
Advantages:
 Very high speed
Disadvantages:
 Very expensive
 Characters fonts cannot be changed
ii)Chain Printer: In this printer, chain of character sets are used so it is called Chain Printer. A
standard character set may have 48, 64, or 96 characters.
Advantages:
 Character fonts can easily be changed.
 Different languages can be used with the same printer.
Disadvantages:
 Noisy
ii)Non-impact Printers: Non-impact printers print the characters without using ribbon.
These printers print a complete page at a time so they are also called as Page Printers.
P.Madhubabu M.C.A & M.Tech 10
Introduction to Programming I-B.Tech, I-Semester
These printers are of two types
a) Laser Printers
b) Inkjet Printers
a)Laser Printers: These are non-impact page printers. They use laser lights to produce the dots
needed to form the characters to be printed on a page.
Advantages:
 Very high speed
 Very high quality output
 Give good graphics quality
 Support many fonts and different character size
Disadvantages:
 Expensive.
 Cannot be used to produce multiple copies of a document in a single printing.
b)Inkjet Printers: Inkjet printers are non-impact character printers based on a relatively new
technology. They print characters by spraying small drops of ink onto paper. Inkjet printers
produce high quality output with presentable features.
They make less noise because no hammering is done and these have many styles of printing
modes available. Colour printing is also possible. Some models of Inkjet printers can produce
multiple copies of printing also.
Advantages:
 High quality printing
 More reliable
Disadvantages:
 Expensive as cost per page is high
 Slow as compared to laser printer

Q8)What are the classification of Computers? (or) What are the types
of Computers?

There are 3 types of computers are available


1) Digital Computers
2) Analog Computers
3) Hybrid Computers
1)Digital Computers: A computer that accepts and processes data that has been converted
into binary numbers. Most computers are digital.
(or)
A computer that stores data in terms of digits (numbers) and proceeds in discrete steps from one
state to the next. The states of a digital computer typically involve binary digits which may take
the form of the presence or absence of magnetic markers in a storage medium. In digital
computers, even letters, words and whole texts are represented digitally.
2)Analog Computers: These are almost extinct today. These are different from a digital
computer because an analog computer can perform several mathematical operations

P.Madhubabu M.C.A & M.Tech 11


Introduction to Programming I-B.Tech, I-Semester
simultaneously. It uses continuous variables for mathematical operations and utilizes mechanical
or electrical energy. These are used in B.P measurements and in Petrol Bunks.
3)Hybrid Computers: The combination of both Digital and Analog is called as Hybrid
Computers. Hybrid computer is a digital computer that accepts analog signals, converts them to
digital and processes them in digital form. This integration is obtained by digital to analog and
analog to digital converter. A hybrid computer may use or produce analog data or digital data.
It accepts a continuously varying input, which is then converted into a set of discrete values for
digital processing.
An example of a hybrid computer is the computer used in hospitals to measure the heartbeat of
the patient. Hybrid Machines are generally used in scientific applications.
Based on the size and memory capacity these are classified into 4 types.
i) Mini Computers
ii) Micro Computers
iii) Main Frame Computers
iv) Super Computers
i)Mini Computers:
 These are small in size and speed has increased
 The speed of CPU is one million instructions per second
 In this magnetic tapes are used as Secondary storage devices
 This is used for CAD(Computer Aided Design) and used for commercial purpose
 The memory capacity is 1mb to 8mb
ii)Micro Computers:
 These are small in size
 In this computational power is less.
 These are also called as Desktop computer
 IC is used as processor
 CPU has small amount of storage space
 Memory capacity is 128kb to 1Mb
 It can process 8bits data or 16bits word length
 These are used as Personal computers
 In this high level languages are used like pascal, fortran
 These are used for banking system, Word processing.
iii)Mainframe Computers:
 These are very large in size
 Memory capacity is 256 Mb
 The speed of processing is very high. ranges from 10 million instructions to 100 million
instructions per second
 The word length is 32 bits-96 bits
 These are used for solving complex problems involved in Engineering and Scientific areas
iV)Super Computers:
 These are very faster computers
 These are designed for scientific applications and are more expensive
 It can process more than 20 million instructions per second
 These can process the operations in parallel
 These are called Very Large Scale Main Frame computers

Q9)What is computer memory? Discuss Classification of Memory?


Computer memory: It is any physical device, used to store data, information or instruction
temporarily or permanently. It is the collection of storage units that stores binary information in
the form of bits.

P.Madhubabu M.C.A & M.Tech 12


Introduction to Programming I-B.Tech, I-Semester
Need a computer memory: In the computer system, we need computer memory to store
various types of data like text, images, video, audio, documents, etc. We can retrieve it when
the data is required.
Classification of Memory: The following figure represents the classification of memory:

1.Primary or Main Memory: Primary memory is also known as the computer system's main
memory that communicates directly within the CPU, Auxiliary memory and the Cache memory.
Main memory is used to kept programs or data when the processor is active to use them. When
a program or data is activated to execute, the processor first loads instructions or programs
from secondary memory into main memory, and then the processor starts execution. Accessing
or executing of data from primary memory is faster because it has a cache or register memory
that provides faster response, and it is located closer to the CPU. The primary memory is
volatile, which means the data in memory can be lost if it is not saved when a power failure
occurs. It is costlier than secondary memory, and the main memory capacity is limited as
compared to secondary memory.
The primary memory is further divided into two parts:
a) RAM (Random Access Memory)
b) ROM (Read Only Memory)
a)Random Access Memory (RAM): Random Access Memory (RAM) is one of the faster
types of main memory accessed directly by the CPU. It is the hardware in a computer device to
temporarily store data, programs or program results. It is used to
read/write data in memory until the machine is working. It is volatile,
which means if a power failure occurs or the computer is turned off,
the information stored in RAM will be lost. All data stored in
computer memory can be read or accessed randomly at any time.
There are two types of RAM:
 SRAM
 DRAM
DRAM: DRAM (Dynamic Random-Access Memory) is a type of RAM that is used for the
dynamic storage of data in RAM. In DRAM, each cell carries one-bit information. The cell is
made up of two parts: a capacitor and a transistor. The size of the capacitor and the transistor is
so small, requiring millions of them to store on a single chip. Hence, a DRAM chip can hold
more data than an SRAM chip of the same size. However, the capacitor needs to be
continuously refreshed to retain information because DRAM is volatile. If the power is switched
off, the data store in memory is lost.
SRAM: SRMA (Static Random-Access Memory) is a type of RAM used to store static data in the
memory. It means to store data in SRAM remains active as long as the computer system has a
power supply. However, data is lost in SRAM when power failures have occurred.
Read-Only Memory (ROM)
P.Madhubabu M.C.A & M.Tech 13
Introduction to Programming I-B.Tech, I-Semester
b)ROM: ROM is a memory device or storage medium that is used to permanently store
information inside a chip. It is a read-only memory that can only read stored information, data
or programs, but we cannot write or modify anything. A ROM contains some important
instructions or program data that are required to start or boot a computer. It is a non-
volatile memory; it means that the stored information cannot be
lost even when the power is turned off or the system is shut down.
Types of ROM: There are five types of Read Only Memory:
a) MROM (Masked Read Only Memory)
b) PROM (Programmable Read Only Memory)
c) EPROM (Erasable and Programmable Read Only Memory)
d) EEPROM (Electrically Erasable and Programmable Read Only
Memory)
e) Flash ROM
a)MROM (Masked Read Only Memory): MROM is the oldest type of read-only memory
whose program or data is pre-configured by the integrated circuit manufacture at the time of
manufacturing. Therefore, a program or instruction stored within the MROM chip cannot be
changed by the user.
b)PROM (Programmable Read Only Memory): It is a type of digital read-only memory, in
which the user can write any type of information or program only once. It means it is the
empty PROM chip in which the user can write the desired content or program only once using
the special PROM programmer or PROM burner device; after that, the data or instruction
cannot be changed or erased.
c)EPROM (Erasable and Programmable Read Only Memory): It is the type of read only
memory in which stored data can be erased and re-programmed only once in the EPROM
memory. It is a non-volatile memory chip that holds data when there is no power supply and
can also store data for a minimum of 10 to 20 years. In EPROM, if we want to erase any stored
data and re-programmed it, first, we need to pass the ultraviolet light for 40 minutes to erase
the data; after that, the data is re-created in EPROM.
d)EEPROM (Electrically Erasable and Programmable Read Only Memory): The EEROM is
an electrically erasable and programmable read only memory used to erase stored data using a
high voltage electrical charge and re-programmed it. It is also a non-volatile memory whose
data cannot be erased or lost; even the power is turned off. In EEPROM, the stored data can be
erased and reprogrammed up to 10 thousand times, and the data erase one byte at a time.
e)Flash ROM: Flash memory is a non-volatile storage memory chip that can be written or
programmed in small units called Block or Sector. Flash Memory is an EEPROM form of
computer memory, and the contents or data cannot be lost when the power source is turned
off. It is also used to transfer data between the computer and digital devices.
2.Secondary Memory: Secondary memory is a permanent storage space to hold a large
amount of data. Secondary memory is also known as external memory that representing the
various storage media (hard drives, USB, CDs, flash drives and DVDs) on which the computer
data and program can be saved on a long term basis.
Types of Secondary Memory:
The following are the types of secondary memory devices:
Hard Disk
i)Hard Disk: A hard disk is a computer's permanent storage device. It is a
non-volatile disk that permanently stores data, programs, and files, and
cannot lose store data when the computer's power source is switched off.
Typically, it is located internally on computer's motherboard that stores and
retrieves data using one or more rigid fast rotating disk platters inside an air-
sealed casing. It is a large storage device, found on every computer or laptop
for permanently storing installed software, music, text documentation, videos, operating system,
and data until the user did not delete.

P.Madhubabu M.C.A & M.Tech 14


Introduction to Programming I-B.Tech, I-Semester
ii)Floppy Disk: A floppy disk is a secondary storage system that
consisting of thin, flexible magnetic coating disks for holding electronic
data such as computer files. It is also known as Floppy Diskette that comes
in three sizes like 8 inches, 5.5 inches and 3.5 inches. The stored data of a
floppy disk can be accessed through the floppy disk drive. Furthermore, it
is the only way through a new program installed on a computer or
backup of the information. However, it is the oldest type of portable
storage device, which can store data up to 1.44 MB. Since most programs were larger, that
required multiple floppy diskettes to store large amounts of data. Therefore, it is not used due
to very low memory storage.
iii)CD (Compact Disc): A CD is an optical disk storage device, stands for
Compact Disc. It is a storage device used to store various data types like audio,
videos, files, OS, Back-Up file, and any other information useful to a computer.
The CD has a width of 1.2 mm and 12 cm in height, which can store
approximately 783 MB of data size. It uses laser light to read and write data
from the CDs.
Types of CDs:
a)CD-ROM (Compact Disc Read Only Memory): It is mainly used for bulk size mass like audio
CDs, software and computer games at the time of manufacture. Users can only read data, text,
music, videos from the disc, but they cannot modify or burnt it.
b)CD-R (Compact Disc Recordable): The type of Compact Disc used to write once by the user;
after that, it cannot be modified or erased.
c)CD-RW (Compact Disc Rewritable): It is a rewritable CD disc, often used to write or delete
the stored data.
iv)DVD Drive/Disc: DVD is an optical disc storage device, stands
for Digital Video Display or Digital Versatile Disc. It has the same size as a
CD but can store a larger amount of data than a compact disc. It was
developed in 1995 by Sony, Panasonic, Toshiba and Philips four electronics
companies. DVD drives are divided into three types, such as DVD ROM
(Read Only Memory), DVD R (Recordable) and DVD RW (Rewritable or
Erasable). It can store multiple data formats like audio, videos, images,
software, operating system, etc. The storing capacity of data in DVD is 4.7 GB to 17 GB.
v)Blu Ray Disc (BD): Blu Ray is an Optical disc storage device used to store a large amount
of data or high definition of video recording and playing other media files. It uses laser
technology to read the stored data of the Blu-ray Disk. It can store more data at a greater
density as compared to CD/ DVD. For example, compact discs allow us to store 700 MB of
data, and in DVDs, it provides up to 8 GB of storage capacity, while Blu-ray Discs provide 28
GB of space to store data.
vi)Pen Drive: A pen drive is a portable device used to permanently store
data and is also known as a USB flash drive. It is commonly used to store
and transfer the data connected to a computer using a USB port. It does
not have any moveable part to store the data; it uses an integrated circuit
chip that stores the data. It allows the users to store and transfer data like
audio, videos, images, etc. from one computer to any USB pen drive. The
storing capacity of pen drives from 64 MB to 128 GB or more.
3.Cache Memory: It is a small-sized chip-based computer memory that lies between the
CPU and the main memory. It is a faster, high performance and temporary
memory to enhance the performance of the CPU. It stores all the data and
instructions that are often used by computer CPUs. It also reduces the access
time of data from the main memory. It is faster than the main memory,
and sometimes, it is also called CPU memory because it is very close to the
CPU chip. The following are the levels of cache memory.

P.Madhubabu M.C.A & M.Tech 15


Introduction to Programming I-B.Tech, I-Semester
4.Register Memory: The register memory is a temporary storage area for storing and
transferring the data and the instructions to a computer. It is the smallest and fastest memory of
a computer. It is a part of computer memory located in the CPU as the form of registers. The
register memory is 16, 32 and 64 bits in size. It temporarily stores data instructions and the
address of the memory that is repeatedly used to provide faster response to the CPU.
Q10)What is a Programming Language?Explain its types?
A programming language is a computer language that is used by programmers (developers) to
communicate with computers. It is a set of instructions written in any specific language ( C,
C++, Java, Python) to perform a specific task.
A programming language is mainly used to develop desktop applications, websites, and mobile
applications.
Types of programming language:
1. Low-level programming language
2. High-level programming language
3. Middle-level programming language
1.Low-level programming language: Low-level language is machine-dependent (0s and
1s) programming language. The processor runs low- level programs directly without the need of
a compiler or interpreter, so the programs written in low-level language can be run very fast.
Low-level language is further divided into two parts –
a) Machine Language
b) Assembly Language
a)Machine Language: Machine language is a type of low-level programming language. It is
also called as machine code or object code. Machine language is easier to read because it is
normally displayed in binary or hexadecimal form (base 16) form. It does not require a
translator to convert the programs because computers directly understand the machine language
programs.
The advantage of machine language is that it helps the programmer to execute the programs
faster than the high-level programming language.
b)Assembly Language: Assembly language (ASM) is also a type of low-level programming
language that is designed for specific processors. It represents the set of instructions in a symbolic
and human-understandable form. It uses an assembler to convert the assembly language to
machine language.
The advantage of assembly language is that it requires less memory and less execution time to
execute a program.
2.High-level programming language: High-level programming language (HLL) is
designed for developing user-friendly software programs and websites. This programming
language requires a compiler or interpreter to translate the program into machine language
(execute the program).
The main advantage of a high-level language is that it is easy to read, write, and maintain.
High-level programming language includes Python, Java, JavaScript, PHP, C#, C++, Objective
C, Cobol, Perl, Pascal, LISP, FORTRAN, and Swift programming language.
A high-level language is further divided into three parts -
i. Procedural Oriented programming language
ii. Object-Oriented Programming language
iii. Natural language
i.Procedural Oriented programming language: Procedural Oriented Programming
(POP) language is derived from structured programming and based upon the procedure call
concept. It divides a program into small procedures called routines or functions.
Procedural Oriented programming language is used by a software programmer to create a
program that can be accomplished by using a programming editor like IDE, Adobe
Dreamweaver, or Microsoft Visual Studio.
The advantage of POP language is that it helps programmers to easily track the program flow
and code can be reused in different parts of the program.
P.Madhubabu M.C.A & M.Tech 16
Introduction to Programming I-B.Tech, I-Semester
Example: C, FORTRAN, Basic, Pascal, etc.
ii.Object-Oriented Programming language: Object-Oriented Programming (OOP)
language is based upon the objects. In this programming language, programs are divided into
small parts called objects. It is used to implement real-world entities like inheritance,
polymorphism, abstraction, etc in the program to makes the program resusable, efficient, and
easy-to-use.
The main advantage of object-oriented programming is that OOP is faster and easier to execute,
maintain, modify, as well as debug.
Example: C++, Java, Python, C#, etc.
iii.Natural language: Natural language is a part of human languages such as English, Russian,
German, and Japanese. It is used by machines to understand, manipulate, and interpret human's
language. It is used by developers to perform tasks such as translation, automatic
summarization, Named Entity Recognition (NER), relationship extraction, and topic
segmentation.
The main advantage of natural language is that it helps users to ask questions in any subject and
directly respond within seconds.
3.Middle-level programming language: Middle-level programming language lies
between the low-level programming language and high-level programming language. It is also
known as the intermediate programming language and pseudo-language.
A middle-level programming language's advantages are that it supports the features of high-level
programming, it is a user-friendly language, and closely related to machine language and human
language.
Example: C, C++, language

Q11) What is an Algorithm? What are the characteristics of Computer?


Give an Example?
Algorithm: Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output. Algorithms are generally created
independent of underlying languages, i.e. an algorithm can be implemented in more than one
programming language.
Characteristics of an Algorithm:
An algorithm should have the below mentioned characteristics:
1.Unambiguous: Algorithm should be clear and unambiguous. Each of its steps (or phases),
and their input/outputs should be clear and must lead to only one meaning.
2.Input: An algorithm should have 0 or more well defined inputs.
3.Output: An algorithm should have 1 or more well defined outputs, and should match the
desired output.
4.Finiteness: Algorithms must terminate after a finite number of steps.
5.Feasibility: Should be feasible with the available resources.
6.Independent: An algorithm should have step-by-step directions which should be
independent of any programming code.
Examples for Algorithm:
Ex1: Write an algorithm to add two numbers entered by user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop

P.Madhubabu M.C.A & M.Tech 17


Introduction to Programming I-B.Tech, I-Semester
Ex2: Write an algorithm to find the largest among three different numbers entered by
user.
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: if a>b
if a>c
Display a is the largest number.
else
Display c is the largest number.
else
if b>c
Display b is the largest number.
else
Display c is the greatest number.
Step 5: Stop
Q12) What is Flowchart ? Give the Example?
Flowchart: A graphical or symbolic representation of a process is called Flowchart.
It Used to design and document complex processes to help the viewers to visualize the logic
of the process
It provides a better understanding of the process and find flaws, bottlenecks, and other less
obvious features within it
Usually drawn in the early stages of formulating computer solutions
Flowchart symbols:
The different flowchart symbols have different conventional meanings.
The various symbols used in Flowchart Designs are given below.
1.Terminal Symbol: In the flowchart, it is represented with the help of a circle for denoting
the start and stop symbol. The symbol given below is used to represent the terminal symbol.

2.Input/output Symbol: The input symbol is used to represent the input data, and the
output symbol is used to display the output operation. The symbol given below is used for
representing the Input/output symbol.

3.Processing Symbol: It is represented in a flowchart with the help of a rectangle box used
to represent the arithmetic and data movement instructions. The symbol given below is used to
represent the processing symbol.

4.Decision Symbol: Diamond symbol is used for represents decision-making statements. The
symbol given below is used to represent the decision symbol.

5.Connector Symbol: The connector symbol is used if flows discontinued at some point and
continued again at another place. The following symbol is the representation of the connector
symbol.

P.Madhubabu M.C.A & M.Tech 18


Introduction to Programming I-B.Tech, I-Semester

6.Flow lines: It represents the exact sequence in which instructions are executed. Arrows are
used to represent the flow lines in a flowchart. The symbol given below is used for representing
the flow lines:

Advantages of Flowchart in C:
Following are the various advantages of flowchart:
1. Communication: A flowchart is a better way of communicating the logic of a
program.
2. Synthesis: Flowchart is used as working models in designing new programs and
software systems.
3. Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual
code in a high-level language.
4. Proper Debugging: Flowcharts help in the debugging process.
5. Effective Analysis: Effective analysis of logical programs can be easily done with the
help of a related flowchart.
6. Proper Documentation: Flowchart provides better and proper documentation. It
consists of various activities such as collecting, organizing, storing, and maintaining all
related program records.
7. Testing: A flowchart helps in the testing process.
8. Efficient program maintenance: The maintenance of the program becomes easy
with the help of a flowchart.
Disadvantages of Flowchart in C:
Following are the various disadvantages of flowchart:
1. Time-consuming: Designing a flowchart is a very time-consuming process.
2. Complex: It isn't easy to draw a flowchart for large and complex programs.
3. There is no standard in the flowchart: there is no standard to determine the
quantity of detail.
4. Difficult to modify: It is very difficult to modify the existing flowchart.
Example: To prepare a flowchart to determine the greatest of two numbers. Here we use the
decision symbol. We also combine the two reads for numbers A and B in one box.
The steps are :
1. Start
2. Get two number A and B.
3. If A > B then print A else print B.
4. Stop

Q13)What is Pseudocode? Explain its advantages?

P.Madhubabu M.C.A & M.Tech 19


Introduction to Programming I-B.Tech, I-Semester
Pseudocode: A Pseudocode is defined as a step-by-step description of an algorithm.
Pseudocode does not use any programming language in its representation instead it uses the
simple English language text as it is intended for human understanding rather than machine
reading.
Pseudocode is the intermediate state between an idea and its implementation(code) in a high-
level language.
Advantages of pseudocode: Some of the important advantages of using pseudocode are
as follows:
i)Easy to write: Writing in pseudocode is typically much easier than writing in a coding
language. It uses plain text that's almost universally understandable.
ii)Easy to convert: Although you write pseudocode in plain text, it still contains the logic for
your code. This means that you can easily convert it into any coding language that you're
familiar with.
iii)Easy to communicate: you can communicate your idea to people who aren't familiar with
coding languages or professionals who specialise in others.
iv)Errors don't matter: With pseudocode, errors are meaningless as they're only meant to
communicate an idea. As long as the reader can still understand what the pseudocode
represents, it's perfectly functional.
v)Simple to change: When using pseudocode, it's quite easy to change the design.
Disadvantages of pseudocode: Some of the key disadvantages of using pseudocode are as
follows:
i)No standard: There's no universal or widely accepted standard for how to write pseudocode.
ii)Time-consuming: Using pseudocode as part of your process often requires more time.
iii)Hard to verify: When you're using proper code, you can easily check if it's working by
executing it.
iv)Difficult to map processes: Although it's easy to read and write, pseudocode is less
capable of displaying processes.
Algorithm for the Program Factorial of a Given Number.
Step 1: start
Step 2: initialize fact = 1
Step 3: input from the user value n
Step 4: for i=1 to i <= n repeat the process
Step 5: fact = fact * i
Step 6: i++ [increament i by one]
Step 7: print fact value
Step 8: stop
Now let’s implement pseudo-code from the above algorithm.
Start program
Declare fact and n
Enter number for n
for i=1 to i <=n
Perform fact = fact * i
Display fact
End program

Q14)Explain how to Creating, Compiling and Executing C Program?


Generally, the programs created using programming languages like C, C++, Java etc., are
written using high level language like English. But, computer cannot understand the high level
language. It can understand only low level language. So, the program written in high level
language needs to be converted into low level language to make it understandable for the
computer. This conversion is performed using either Interpreter or Compiler.
Popular programming languages like C, C++, Java etc., use compiler to convert high
P.Madhubabu M.C.A & M.Tech 20
Introduction to Programming I-B.Tech, I-Semester
level language instructions into low level language instructions. Compiler is a program that
converts high level language instructions into low level language instructions. Generally,
compiler performs two things, first it verifies the program errors, if errors are found, it returns
list of errors otherwise it converts the complete code into low level language.
To create and execute C programs in Windows Operating System, we need to install
Turbo C software. We use the following steps to create and execute C programs in Windows
OS…

Step 1: Creating Source Code


Source code is a file with C programming instructions in high level language. To create
source code, we use any text editor to write the program instructions. The instructions written
in the source code must follow the C programming language rules. The following steps are used
to create source code file in Windows OS…
 Click on Start button
 Select Run
 Type cmd and press Enter
 Type cd c:\TC\bin in the command prompt and press Enter
 Type TC press Enter
 Click on File -> New in C Editor window
 Type the program
 Save it as FileName.c or Filename.cpp (Use shortcut key F2 to save)
Step 2: Compile Source Code (Alt + F9)
Compilation is the process of converting high level language instructions into low level
language instructions. We use the shortcut key Alt + F9 to compile a C program in Turbo C.
Whenever we press Alt + F9, the source file is going to be submitted to the Compiler. On
receiving a source file, the compiler first checks for the Errors. If there are any Errors then
compiler returns List of Errors, if there are no errors then the source code is converted
into object code and stores it as file with .obj extension. Then the object code is given to
the Linker. The Linker combines both the object code and specified header file code and
generates an Executable file with .exe extension.
Step 3: Executing / Running Executable File (Ctrl + F9)
After completing compilation successfully, an executable file is created with .exe extension. The
processor can understand this .exe file content so that it can perform the task specified in the
source file.
We use a shortcut key Ctrl + F9 to run a C program. Whenever we press Ctrl + F9,
the .exe file is submitted to the CPU. On receiving .exe file, CPU performs the task according to
the instruction written in the file. The result generated from the execution is placed in a window
called User Screen.
Step 4: Check Result (Alt + F5)
After running the program, the result is placed into User Screen. Just we need to open the User
Screen to check the result of the program execution. We use the shortcut key Alt + F5 to open
the User Screen and check the result.
P.Madhubabu M.C.A & M.Tech 21
Introduction to Programming I-B.Tech, I-Semester
Execution Process of a C Program:
When we execute a C program it undergoes with following process…

The file which contains c program instructions in high level language is said to be source
code. Every c program source file is saved with .c extension, for example Sample.c.
Whenever we press Alt + F9 the source file is submitted to the compiler. Compiler checks
for the errors, if there are any errors, it returns list of errors, otherwise generates object code in
a file with name Sample.obj and submit it to the linker. Linker combines the code from specified
header file into object file and generates executable file as Sample.exe. With this compilation
process completes.
Now, we need to Run the executable file (Sample.exe). To run a program we press Ctrl
+ F9. When we press Ctrl + F9 the executable file is submitted to the CPU. Then CPU performs
the task according to the instructions written in that program and place the result into
UserScreen.
Then we press Alt + F5 to open UserScreen and check the result of the program.

Q15) Explain about Datatypes in C Language?


A data type represents the type of the variable, means what value that variable will
store. All ‘C’ compilers support variety of data types. Generally data is represented using
numbers and characters. The number may be integer or real. The different compilers support
the different data types.

Classification of data types:


1. Primary Datatypes
1. User-defined Datatypes
1.Primary Datatypes: The primary datatypes are also called as simple datatypes or standard
datatype

P.Madhubabu M.C.A & M.Tech 22


Introduction to Programming I-B.Tech, I-Semester

These primary data types are divided into 3 categories . They are:
a)Integral Datatypes
b)Floating point Datatypes
c)Character Datatypes
a)Integral Datatypes: Integral data types are used to allocate memory for integer values.
int, short int, long int are signed datatypes used to store positive values and also negative
values.
unsigned int, unsigned short int, unsigned long int types allows only positive values.
These integer datatype can also accepts octal values, hexa decimal values.
signed int – 2bytes -> -32,768 to +32767
unsigned int – 2bytes -> 0 to 65535
Syntax: Datatype variable-name; (or) Datatype identifier;
Ex: int a=26; //decimal representation
int a=032; //octal representation
int a=0x1a; //hexa decimal representation
b)Floating point Datatypes: float, double, long double are the floating datatypes, which are
used to store decimal values. float takes 4 bytes of memory and double takes 8 bytes of
memory it is capable of representing about twice as much precision as a float. The long double
takes 10 bytes of memory.
Ex: float a;
a = 0.143;

float pi;
double pi_sqr;

pi = 3.1417;
pi_sqr = pi * pi;

c)Character Data Types: signed char, unsigned char are the character datatypes.
Signed char – 1 byte -128 to +127
Unsigned char – 1 byte 0 to 255
signed char is used to store alphabets and unsigned char is used to store unsigned integer value
upto 255.
It allocates 1 byte memory for single character and also allocate memory for 1 byte to
unsigned integer. In ‘c’ language every character has a decimal value called ASCII(American
Standard Code Information Interchange)
Ex: char ch1 = ‘a’;

P.Madhubabu M.C.A & M.Tech 23


Introduction to Programming I-B.Tech, I-Semester
unsigned char ch2 = 25;

printf(“%c”,ch1);
printf(“%d”,ch2);
2.UserDefined Datatypes: structures, unions, typedef are examples to Userdefined datatypes.
The c language provides to create your own names for data types with this typedef keyword.
Ex: typedef int integer;
integer a, b;
Makes the name integer a synonym for int. it is used same as int.
The typedef declaration does not create a new type in any sense. It adds a new name for the
existing type. It makes easy to identify which purpose the variable is used.

Q16) Explain about Variables?


Variable: A variable is a name of the memory location. It is used to store data. Its value can
be changed, and it can be reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
Declaration of a variable:
Synatx: datatype variable1, variable2,…;
Example:
int a; int a,b,c;
float b; (or) float n,m,o;
char c; char x,y,z;
Here, a, b, c are variables. The int, float, char are the data types.
Assinging of Variables:
We can also provide values while declaring the variables as given below:
int a=10,b=20;//declaring 2 variable of integer type
float f=20.8;
char c='A';
Rules for defining variables:
A variable can have alphabets, digits, and underscore.
A variable name can start with the alphabet, and underscore only. It can't start with a digit.
No whitespace is allowed within the variable name.
A variable name must not be any reserved word or keyword, e.g. int, float, etc.
Valid variable names:
int a;
int _ab;
int a30;
Invalid variable names:
int 2;
int a b;
int long;
Types of Variables in C:
There are 5 types of variables in c:
a) local variable
b) global variable
c) static variable
d) automatic variable
e) external variable
a)Local Variable:
A variable that is declared inside the function or block is called a local variable.
It must be declared at the start of the block.

P.Madhubabu M.C.A & M.Tech 24


Introduction to Programming I-B.Tech, I-Semester
void function1()
{
int x=10;//local variable
}
You must have to initialize the local variable before it is used.
b)Global Variable:
A variable that is declared outside the function or block is called a global variable.
Any function can change the value of the global variable. It is available to all the functions.
It must be declared at the start of the block.
int value=20;//global variable
void function1()
{
int x=10;//local variable
}
c)Static Variable:
A variable that is declared with the static keyword is called static variable.
It retains its value between multiple function calls.
void function1()
{
int x=10;//local variable
static int y=10;//static variable
x=x+1;
y=y+1;
printf("%d,%d",x,y);
}
If you call this function many times, the local variable will print the same value for each
function call, e.g, 11,11,11 and so on. But the static variable will print the incremented value in
each function call, e.g. 11, 12, 13 and so on.
d)Automatic Variable:
All variables in C that are declared inside the block, are automatic variables by default. We
can explicitly declare an automatic variable using auto keyword.
void main()
{
int x=10;//local variable (also automatic)
auto int y=20;//automatic variable
}
e)External Variable:
We can share a variable in multiple C source files by using an external variable.
To declare an external variable, you need to use extern keyword.
myfile.h
extern int x=10;//external variable (also global)
program1.c
#include "myfile.h"
#include <stdio.h>
void printValue()
{
printf("Global variable: %d", global_variable);
}

P.Madhubabu M.C.A & M.Tech 25


Introduction to Programming I-B.Tech, I-Semester
Q17) Explain about ‘C’ Tokens ?
In a passage of text, individual words and punctuation marks are called tokens or lexical units.
Similarly, the smallest individual unit in a c program is known as a token or a lexical unit. C
tokens can be classified as follows:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators

1.Keywords: The C keywords are reserved words by the compiler. All the C keywords have
been assigned fixed meaning. The keywords cannot be used as variable names because they
have been assigned fixed jobs. The C language has 32 keywords.

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

2.Identifiers: Identifier can be defined as the name of the variable, which holds a value and
stores that value in the memory.
Example: char ch=’x’;
int a=10;
float b=5.7;
double c=234234.5656;
in the above example, variable names: ch, a, b, c are called as Identifiers.

Rules for declaring the identifiers:


 The first character of an identifier should be either an alphabet or an underscore, and
then it can be followed by any of the character, digit, or underscore.
 It should not begin with any numerical digit.
 In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say
that identifiers are case sensitive.
 Commas or blank spaces cannot be specified within an identifier.
 Keywords cannot be represented as an identifier.
 The length of the identifiers should not be more than 31 characters.
 Identifiers should be written in such a way that it is meaningful, short, and easy to read.

3.Constants: A constant is a fixed value that cannot be altered during the execution of a
program. There are several types of constants in C.

P.Madhubabu M.C.A & M.Tech 26


Introduction to Programming I-B.Tech, I-Semester
Constant Example
Integer constant 10, 11, 34, etc.
Floating-point constant 45.6, 67.8, 11.2, etc.
Octal constant 011, 088, 022, etc.
Hexadecimal constant 0x1a, 0x4b, 0x6b, etc.
Character constant 'a', 'b', 'c', etc.
String constant "java", "c++", ".net", etc.

Types of Constants: There are mainly 2 types of constants. They are:


3.1.Numeric Constants
3.2.Character Constants
3.1.Numeric Constants: These are two types. They are:
3.1.1.Integer Constants
3.1.2.Real Constants
3.1.1. Integer Constants:
An integer constant refers to a sequence of digits. There are three types of integer’s namely:
a) decimal integer
b) octal integer
c) hexadecimal integer.
a)Decimal Integers: Decimal integers consists of set of digits 0 through 9, preceded by an
optional – or + sign.
Ex: 10, 20, +30, -15 etc.
b)Octal Integers: An octal integer constant consists of any combination of digits from the set 0
through 7, with a leading 0.
Ex: 037, 0456, 0, 0551 etc.
c)Hexa Decimal Integers: A sequence of digits preceded by 0x or 0X is considered as hexa
decimal integer. They may also include alphabets ‘A’ to ‘F’ or ‘a’ to ‘f’. The letters ‘A’ to ‘F’
represent the numbers 10 through 15.
Ex: 0x2, 0x9F, 0xbcd etc.
3.1.2.Real Constants: Real constants are often known as floating point constants. The real
constants can be written in exponential notation, which contains a fractional part and an
exponential part.
Ex: 2.5, 5.521, 2456.123

3.2)Character Constants:
a)Single character constants: A character constant is a single constant is a single character.
They are also represented with a single digit or a single symbol or white space enclosed within
a pair of single quote marks.
Ex: ‘a’, ‘A’, ‘8’ etc.

b) String constants: String constants are sequence of character enclosed within a double
quote marks.
Ex: “career”, “welcome” etc.

c)Back slash Character Constants:


C supports some special backslash character constants that are used in output functions.

P.Madhubabu M.C.A & M.Tech 27


Introduction to Programming I-B.Tech, I-Semester

4.Strings: A String is an array of characters ended with a null character(\0). This null
character indicates that string has ended. Strings are always enclosed with double quotes(“ “).
Let us see how to declare String in C language:
Examples:
char string[20] = {‘s’,’t’,’u’,’d’,’y’, ‘\0’};
char string[20] = “demo”;
char string[] = “demo”;
5.Special Symbols: The following special symbols are used in C having some special
meaning and thus, cannot be used for some other purpose.
Some special characters are used in C, and they have a special meaning which cannot be used
for another purpose.
i) Square brackets[]: The opening and closing brackets represent the single and
multidimensional subscripts.
ii) Simple brackets ( ) : It is used in function declaration and function calling. For example,
printf() is a pre-defined function.
iii) Curly braces { } : It is used in the opening and closing of the code. It is used in the
opening and closing of the loops.
iv) Comma (,): It is used for separating for more than one statement and for example,
separating function parameters in a function call, separating the variable when printing
the value of more than one variable using a single printf statement.
v) Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that
we are using the header file.
vi) Asterisk (*): This symbol is used to represent pointers and also used as an operator for
multiplication.
vii) Tilde (~): It is used as a destructor to free memory.
viii) Period (.): It is used to access a member of a structure or a union.
6.Operators: C operators are symbols that triggers an action when applied to C variables
and other objects. The data items on which operators act upon are called operands.
Depending on the number of operands that an operator can act upon, operators can be
classified as follows:
i)Unary Operators: A unary operator is an operator applied to the single operand.
Example:

increment operator (++),

decrement operator (--),

sizeof,

(type)*.
ii)Binary Operators: The binary operator is an operator applied between two operands. The
following is the list of the binary operators:
a) Arithemetic Operators
b) Relational Operators
c) Logical Operators

P.Madhubabu M.C.A & M.Tech 28


Introduction to Programming I-B.Tech, I-Semester
d) Assignment Operators
e) Bitwise Operators
iii)Ternary Operators: These operators requires three operands to act upon.
Example: ? : is the ternary operator.

Q18)What are the Input/OutPut Statements in C language?


Input and Output statements are used to read and write the data in C programming. These are
embedded in stdio.h (standard Input/Output header file). There are mainly two types of
Input/Output functions. They are:
1. Formatted I/O functions
2. Unformatted I/O functions
1)Formatted input/output functions: The formatted input/output functions read and
write all types of data values. They require conversion symbol to identify the data type. Hence,
they can be used for both reading and writing the data of all types. The formatted functions
return the values after execution. There are 2 types of formatted I/O functions. They are:
a) scanf ( )
b) printf ( )
a) scanf(): scanf( ) function is used to read any type of data from the keyboard. This function
should have atleast two parameters. First one is the control string which has ‘code characters’.
The other parameter is ‘variable name’s. There must be atleast one variable name should be
present.
Syntax: scanf("control strings",arg1,arg2,..............argn);
Ex: scanf("control strings",&v1,&v2,&v3,................&vn);
Where arg1,arg2,..........argn are the arguments for reading and v1,v2,v3,........vn all are the
variables.
The scanf() format code (spedifier) is as shown in the below table:

Format Code Meaning


%c To read a single character
%d To read a signed decimal integer (short)
%ld To read a signed long decimal integer
%e To read a float value exponential
%f To read a float (short0 or a single precision value
%lf To read a double precision float value
%g To read double float value
%h To read short integer
%i To read an integer (decimal, octal, hexadecimal)
%o To read an octal integer only
%x To read a hexadecimal integer only
%u To read unsigned decimal integer (used in pointer)
%s To read a string
%[..] To read a string of words from the defined range
%[^] To read string of words which are not from the defined range
Example:
/*Program to illustrate the use of formatted code by using the formatted scanf() function */
#include<stdio.h>

P.Madhubabu M.C.A & M.Tech 29


Introduction to Programming I-B.Tech, I-Semester
#include<conio.h>
void main()
{
char n,name[20];
int abc;
float xyz;
printf("Enter the single character, name, integer data and real value");
scanf("\n%c%s%d%f", &n,name,&abc,&xyz);
getch();
}
b)printf(): This ia an output function. It is used to display a text message and to display the
mixed type (int, float, char) of data on screen. The general syntax is as:
Syntax: printf("control strings",&v1,&v2,&v3,................&vn);
or
printf("Message line or text line");
Ex: printf(“Total=”%d”,sum);
or
printf(“Hello World”);
Where v1,v2,v3,........vn all are the variables.
The control strings use some printf() format codes or format specifiers or conversion characters.
These all are discussed in the below table as:
Format Code Meaning
%c To read a single character
%s To read a string
%d To read a signed decimal integer (short)
%ld To read a signed long decimal integer
%f To read a float (short0 or a single precision value
%lf To read a double precision float value
%e To read a float value exponential
%g To read double float value
%o To read an octal integer only
%x To read a hexadecimal integer only
%u To read unsigned decimal integer (used in pointer)
Example:
/*Below the program which show the use of printf() function*/
#include<stdio.h>
#include<conio.h>
main()
{
int a;
float b;
char c;
printf("Enter the mixed type of data");
scanf("%d",%f,%c",&a,&b,&c);
getch();
}
2)Unformatted input/output functions: The unformatted input/output functions only
work with the character data type. They do not require conversion symbol for identification of

P.Madhubabu M.C.A & M.Tech 30


Introduction to Programming I-B.Tech, I-Semester
data type because they work only with character data type. There is no need to convert the
data. There are mainly six unformatted I/O functions discussed as follows:
a) getchar( )
b) getche( )
c) getch( )
d) gets( )
e) putch( )
f) putchar( )
g) puts( )
a)getchar(): This function is an Input function. It is used for reading a single character from
the keyborad. It is buffered function. Buffered functions get the input from the keyboard and
store it in the memory buffer temporally until you press the Enter key.
syntax: v=getchar();
where v is the variable of character type.
Example: char n;
n=getchar();
Example Program: /*To read a single character from the keyboard using the getchar()
function*/
#include<stdio.h>
#include<conio.h>
void main()
{
char n;
n=getchar();
}
b)putchar(): This function is an output function. It is used to display a single character on the
screen.
Syntax: putchar(v);
where v is the variable of character type.
Example: char n;
putchar(n);
Example program: /*Program illustrate the use of getchar() and putchar() functions*/
#include<stdio.h>
#include<conio.h>
void main()
{
char n;
n=getchar();
putchar(n);
}
c)gets(): This function is an input function. It is used to read a string from the keyboar. It is
also buffered function. It will read a string, when you type the string from the keyboard and
press the Enter key from the keyboard. It will mark nulll character ('\0') in the memory at the
end of the string, when you press the enter key.
Syntax: gets(v);
where v is the variable of character type.
Example: char n[20];
gets(n);
Example Program: /*Program to explain the use of gets() function*/
#include<stdio.h>
#include<conio.h>
void main()
{
P.Madhubabu M.C.A & M.Tech 31
Introduction to Programming I-B.Tech, I-Semester
char n[20];
gets(n);
}
d)puts(): This is an output function. It is used to display a string inputted by gets() function.
It is also used to display an text (message) on the screen for program simplicity. This function
appends a newline ("\n") character to the output.
Syntax: puts(v);
or
puts("text line");
where v is the variable of character type.
Example Program: /*Program to illustrate the concept of puts() with gets() functions*/
#include<stdio.h>
#include<conio.h>
void main()
{
char name[20];
puts("Enter the Name");
gets(name);
puts("Name is :");
puts(name);
}
OUTPUT IS:
Enter the Name
Laura
Name is:
Laura
e)getch(): This is also an input function. This is used to read a single character from the
keyboard like getchar() function. But getchar() function is a buffered is function, getchar()
function is a non-buffered function. The character data read by this function is directly assign to
a variable rather it goes to the memory buffer, the character data directly assign to a variable
without the need to press the Enter key.
Another use of this function is to maintain the output on the screen till you have not press the
Enter Key.
Syntax: v = getch();
where v is the variable of character type.
Example Program: /*Program to explain the use of getch() function*/
#include<stdio.h>
#include<conio.h>
void main()
{
char n;
puts("Enter the Char");
n=getch();
puts("Char is :");
putchar(n);
getch();
}
OUTPUT IS:
Enter the Char
Char is L
f)getche(): All are same as getch(0 function execpt it is an echoed function. It means when
you type the character data from the keyboard it will visible on the screen.
Syntax: v = getche();
P.Madhubabu M.C.A & M.Tech 32
Introduction to Programming I-B.Tech, I-Semester
where v is the variable of character type.
Example: /*Program to explain the use of getch() function*/
#include<stdio.h>
#include<conio.h>
void main()
{
char n;
puts("Enter the Char");
n=getche();
puts("Char is :");
putchar(n);
getche();
}
OUTPUT IS:
Enter the Char L
Char is L

Q19)Explain the structure of ‘c’ program?


Basic Structure of C Program: Every C program contains a number of several building
blocks known as functions. Each function of it perform task independently. A function is a
subroutine that may consist of one or more statements. A C program may have the following
sections.

1)Documentation Section
2)Link Section
3)Definition Section
4)Global Declaration section
5)Function main()
5.1)Declaration Part
5.2)Executable Part
6)Sub-Program Section

P.Madhubabu M.C.A & M.Tech 33


Introduction to Programming I-B.Tech, I-Semester
1.Documentation Section: The documentation section consists of a set of comment lines
giving the name of the program. Comments are providing description of the program.
There are two types of comments in C
 Single Line comment
 Multi Line comment
Single Line Comment: These comments are for marking a single line as a comment. These
comments start with double slash symbol // and after this, whatever is written till the end of the
line is taken as a comment.
Ex: // this is single comment line.
Multi Line Comment: These comments are used for representing several lines as comments.
These comments start with /* and end with */. In between /* and */, whatever is written is
treated as a multi line comment.
Ex: /*
-------- line1--------
--------line2--------
--------line3--------
*/
2.Link Section: The link section provides instructions to the compiler to link functions from
the system library i.e. header file. C program depends upon some header files for function
definition that are used in program. Each header file by default is extension with .h. The file
should be include using #include directive.
Ex: #include<stdio.h>
#include<conio.h>
3.Definition Section: The definition section definition defines all symbolic constants.
Ex: #define PIE 3.14
in the above example PIE is a symbolic constant. Its value is 3.14. it is a fixed value.
Which means it can not be modified.
4.Global Declaration section: This section declares some variables that are used in more
than one function. These variables are known as global variables. These variables must be
declared outside of all the function.
Ex: int a=10; //here ‘a’ is gloabal variable
Void main()
{
}
5.main() Function section: Every program written in C language must contain main ( )
function. Empty parenthesis ({ }) after main are necessary. The function main() is the starting
point of every ‘C’ program. The execution of the program always begins with the function
main(). The program execution starts with the opening brace ’{‘ and ends with the closing brace
‘}’.
Ex: void main()
{
//executable statements
}
5.1.Declaration Part: The declaration part declares the entire variables that are used in
executable part. The initializations of variables are also done in this section. The initialization
means providing initial value to the variables.
Ex: void main()
{
Int a=10; //declaration part
//executable statements
}

P.Madhubabu M.C.A & M.Tech 34


Introduction to Programming I-B.Tech, I-Semester
5.2.Executable Part: This part contains the statement following the declaration of the
variables. This part contains a set of statements or a single statement. These statements are
enclosed between the braces.
Ex: void main()
{
Int a=10; //declaration part
//executable part
}
6.Sub-Program Section: The functions defined by the user are called user-defined functions.
These functions are generally defined after the main ( ) function. They can also be defined
before main() function. This portion is not compulsory.
Ex: void main()
{
Int a=10; //declaration part
//executable part
}
Add() //subprogram
{
//function body
}

Q20)What is an Operator? List out various operators used in ‘C’?


Operator: An operator is a symbol used to perform mathematical and logical operations in a
program. That means an operator is a special symbol that tells to the compiler to perform
mathematical or logical operations. C programming language supports rich set of operators that
are classified as follows...
1. Arithematic Operators
2. Relational Operators
3. Logical Operators
4. Increment & Decrement Operators
5. Assignment Operators
6. Bitwise Operators
7. Conditional Operator
8. Special Operators
1.Arithematic Operators (+, -, *, /, %): The arithematic operators are the symbols
that are used to perform basic mathematical operations like addition, subtraction,
multiplication, division and percentage modulo. The following table provides information
about arithematic operators...
Operator Meaning Example
+ Addition 10 + 5 = 15
- Subtraction 10 - 5 = 5
* Multiplication 5 * 10 = 50
/ Division 10 / 5 = 2
% Remaider of Division 5%2=1
⇒ The addition operator can be used with numerical data types and character data type. When
it is used with numerical values, it performs mathematical addition and when it is used with
character data type values, it performs concatination (appending).
⇒ The remainder of division operator is used with integer data type only.
2.Relational Operators (<, >, <=, >=, ==, !=): The relational operators are
the symbols that are used to compare two values. That means, the relational operators are used
P.Madhubabu M.C.A & M.Tech 35
Introduction to Programming I-B.Tech, I-Semester
to check the relationship between two values. Every relational operator has two results TRUE or
FALSE. In simple words, the relational operators are used to define conditions in a program. The
following table provides information about relational operators...
Operator Meaning Example
Returns TRUE if first value is smaller than second value 10 < 5 is
<
otherwise returns FALSE FALSE
Returns TRUE if first value is larger than second value
> 10 > 5 is TRUE
otherwise returns FALSE
Returns TRUE if first value is smaller than or equal to 10 <= 5 is
<=
second value otherwise returns FALSE FALSE
Returns TRUE if first value is larger than or equal to 10 >= 5 is
>=
second value otherwise returns FALSE TRUE
Returns TRUE if both values are equal otherwise returns 10 == 5 is
==
FALSE FALSE
Returns TRUE if both values are not equal otherwise 10 != 5 is
!=
returns FALSE TRUE
3.Logical Operators (&&, ||, !): The logical operators are the symbols that are used to
combine multiple conditions into one condition. The following table provides information
about logical operators...
Operator Meaning Example
Logical AND - Returns TRUE if all conditions are 10 < 5 && 12 > 10 is
&&
TRUE otherwise returns FALSE FALSE
Logical OR - Returns FALSE if all conditions are 10 < 5 || 12 > 10 is
||
FALSE otherwise returns TRUE TRUE
Logical NOT - Returns TRUE if condition is FLASE !(10 < 5 && 12 >
!
and returns FALSE if it is TRUE 10) is TRUE
⇒ Logical AND - Returns TRUE only if all conditions are TRUE, if any of the conditions is FALSE
then complete condition becomes FALSE.
⇒ Logical OR - Returns FALSE only if all conditions are FALSE, if any of the conditions is TRUE
then complete condition becomes TRUE.
4.Increment & Decrement Operators (++, --): The increment and decrement
operators are called as unary operators because, both needs only one operand. The increment
operators adds one to the existing value of the operand and the decrement operator subtracts
one from the existing value of the operand. The following table provides information about
increment and decrement operators...
Operator Meaning Example
int a = 5;
++ Increment - Adds one to existing value
a++; ⇒ a = 6
int a = 5;
-- Decrement - Subtracts one from existing value
a--; ⇒ a = 4
The increment and decrement operators are used infront of the operand (++a) or after the
operand (a++). If it is used infront of the operand, we call it as pre-increment or pre-
decrement and if it is used after the operand, we call it as post-increment or post-decrement.
Pre-Increment or Pre-Decrement: In case of pre-increment, the value of the variable is
increased by one before the expression evaluation. In case of pre-decrement, the value of the
variable is decreased by one before the expression evaluation. That means, when we use pre

P.Madhubabu M.C.A & M.Tech 36


Introduction to Programming I-B.Tech, I-Semester
increment or pre decrement, first the value of the variable is incremented or decremented by
one, then modified value is used in the expression evaluation.
Example:
#include <stdio.h>
void main()
{
int i=5;
printf("%d\t",++i);
printf("%d",--i);
}
Output: 6 5
Post-Increment or Post-Decrement: In case of post-increment, the value of the variable is
increased by one after the expression evaluation. In case of post-decrement, the value of the
variable is decreased by one after the expression evaluation. That means, when we use post-
increment or post-decrement, first the expression is evaluated with existing value, then the value
of the variable is incremented or decremented by one.
Example:
#include <stdio.h>
void main(){
int i=5;
printf("%d\t",i++);
printf(“%d”,i--);
}
Output: 6 6
5.Assignment Operators (=, +=, -=, *=, /=, %=): The assignment operators are
used to assign right hand side value (Rvalue) to the left hand side variable (Lvalue). The
assignment operator is used in different variants along with arithematic operators. The following
table describes all the assignment operators in C programming language.
Operator Meaning Example
= Assign the right hand side value to left hand side variable A = 15
Add both left and right hand side values and store the A+=10
+=
result into left hand side variable ⇒ A=A+10
Subtract right hand side value from left hand side
A-=B
-= variable value and store the result into left hand side
⇒ A=A-B
variable
Multiply right hand side value with left hand side
A*=B
*= variable value and store the result into left hand side
⇒ A=A*B
variable
Divide left hand side variable value with right hand side
A/=B
/= variable value and store the result into left hand side
⇒ A=A/B
variable
Divide left hand side variable value with right hand side
A%=B
%= variable value and store the remainder into left hand
⇒ A=A%B
side variable
6.Bitwise Operators (&, |, ^, ~, >>, <<): The bitwise operators are used to
perform bit level operations in c programming language. When we use the bitwise operators,
the operations are performed based on the binary values. The following table describes all the
bitwise operators in C programming language.
Let us consider two variables A and B as A = 25 (11001) and B = 20 (10100)

P.Madhubabu M.C.A & M.Tech 37


Introduction to Programming I-B.Tech, I-Semester
Operator Meaning Example
the result of Bitwise AND is 1 if all the bits are 1 otherwise it is
& A&B⇒16 (10000)
0
| the result of Bitwise OR is 0 if all the bits are 0 otherwise it is 1 A|B⇒ 29 (11101)
the result of Bitwise XOR is 0 if all the bits are same otherwise
^ A^B⇒ 13 (01101)
it is 1
the result of Bitwise once complement is nagation of the bit
~ ~A⇒ 6 (00110)
(Flipping)
the Bitwise left shift operator shifts all the bits to the left by A<<2⇒100
<<
specified number of positions (1100100)
the Bitwise right shift operator shifts all the bits to the right by A>>2⇒ 6
>>
specified number of positions (00110)

7.Conditional Operator (?:): The conditional operator is also called as ternary


operator because it requires three operands. This operator is used for decision making. In this
operator, first we verify a condition, then we perform one operation out of the two operations
based on the condition result. If the condition is TRUE the first option is performed, if the
condition is FALSE the second option is performed. The conditional operator is used with the
following syntax...
Condition ? TRUE Part : FALSE Part ;
Example:
A = (10<15) ? 100 : 200 ; ⇒ A value is 100
8.Special Operators (sizeof, pointer, comma, dot):
The following are the special operators in c programming language...
a)sizeof operator: This operator is used to find the size of the memory (in bytes) allocated
for a variable. This operator is used with the following syntax...
Syntax: sizeof(variableName);
Example: sizeof(A); ⇒ result is 2 if A is an integer
b)Pointer operator (*): This operator is used to define pointer variables in c programming
language.
c)Comma operator (,): This operator is used to separate variables while they are declaring,
separate the expresions in function calls etc..
d)Dot operator (.): This operator is used to access members of sructure or union.

Q21)Explain about Type Conversion/casting in C?


Type Conversion in C: Type conversion in C is the process of converting one data type
to another. The type conversion is only performed to those data types where conversion is
possible. Type conversion is performed by a compiler. In type conversion, the destination data
type can’t be smaller than the source data type. Type conversion is done at compile time and it
is also called widening conversion because the destination data type can’t be smaller than the
source data type. There are two types of Conversion:
1. Implicit Type Conversion
2. Explicit Type Conversion

1.Implicit Type Conversion: It Also known as ‘automatic type conversion’.


It is Done by the compiler on its own, without any external trigger from the user.
Generally takes place when in an expression more than one data type is present. In such
conditions type conversion (type promotion) takes place to avoid loss of data.

P.Madhubabu M.C.A & M.Tech 38


Introduction to Programming I-B.Tech, I-Semester
All the data types of the variables are upgraded to the data type of the variable with the
largest data type.
It is possible for implicit conversions to lose information, signs can be lost (when signed is
implicitly converted to unsigned), and overflow can occur (when long is implicitly converted to
float).

Occurrences of Implicit Type Conversion in C:


Implicit type conversion is also called automatic type conversion. Some of its few occurrences
are mentioned below:
 Conversion Rank
 Conversions in Assignment Expressions
 Conversion in other Binary Expressions
 Promotion
 Demotion
Example of Type Implicit Conversion:
// An example of implicit conversion
#include <stdio.h>
int main()
{
int x = 10; // integer x
char y = 'a'; // character c

// y implicitly converted to int. ASCII


// value of 'a' is 97
x = x + y;

// x is implicitly converted to float


float z = x + 1.0;

printf("x = %d, z = %f", x, z);


return 0;
}

Output:
x = 107, z = 108.000000

P.Madhubabu M.C.A & M.Tech 39


Introduction to Programming I-B.Tech, I-Semester
2.Explicit Type Conversion: This process is also called type casting and it is user-defined.
Typecasting in C is the process of converting one data type to another data type by the
programmer using the casting operator during program design.
In typecasting, the destination data type may be smaller than the source data type when
converting the data type to another data type, that’s why it is also called narrowing conversion.

Syntax/Declaration:
destination_datatype = (target_datatype)variable;
target_datatype indicated the data type to which the final result is converted.

Example for explicit type casting:


#include<stdio.h>
int main()
{
double x = 1.2;
// Explicit conversion from double to int
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}

Output:
sum = 2

Q22)Explain differences between Type Conversion and Type casting in


C?
S.NO TYPE CASTING TYPE CONVERSION

In type casting, a data type is converted Whereas in type conversion, a data type is
1. into another data type by a programmer converted into another data type by a
using casting operator. compiler.

Type casting can be applied


Whereas type conversion can only be
2. to compatible data types as well
applied to compatible datatypes.
as incompatible data types.

In type casting, casting operator is


Whereas in type conversion, there is no
3. needed in order to cast a data type to
need for a casting operator.
another data type.

P.Madhubabu M.C.A & M.Tech 40


Introduction to Programming I-B.Tech, I-Semester
S.NO TYPE CASTING TYPE CONVERSION

In typing casting, the destination data


Whereas in type conversion, the
type may be smaller than the source data
4. destination data type can’t be smaller than
type, when converting the data type to
source data type.
another data type.

Type casting takes place during the Whereas type conversion is done at the
5.
program design by programmer. compile time.

Type casting is also called narrowing Whereas type conversion is also called
conversion because in this, the widening conversion because in this, the
6.
destination data type may be smaller destination data type can not be smaller
than the source data type. than the source data type.

Whereas type conversion is less used in


Type casting is often used in coding and
7. coding and competitive programming as it
competitive programming works.
might cause incorrect answer.

Type casting is more efficient and Whereas type conversion is less efficient
8.
reliable. and less reliable.

Q23)Explain Problem solving Strategies(Top Down & Bottom Up


approaches) in Pogramming?
In the context of programming, "Top-Down" and "Bottom-Up" are different approaches to
design and develop software solutions. These techniques are not specific to the C language but
can be applied to various programming languages, including C. Let's explore each approach:
1.Top-Down Approach: The top-down approach involves breaking down a complex
problem into smaller and more manageable sub-problems. You start by designing the overall
structure and main modules of the program, defining the high-level logic first. Then, you
gradually expand each module into more detailed sub-modules until you reach the level of
individual functions or code snippets.
Advantages of Top-Down Approach:
It emphasizes a clear understanding of the problem's high-level structure and
requirements.
 It facilitates better organization and division of work among team members.
 It allows parallel development of different modules by different team members.
2.Bottom-Up Approach: The bottom-up approach takes the opposite direction
compared to the top-down approach. Here, you begin by solving individual sub-problems or
implementing specific functionalities first. These smaller components are then gradually
integrated to create larger and more comprehensive modules, until finally, the complete
program is constructed.
Advantages of the Bottom-Up Approach:
 It encourages code reusability, as individual components can be easily reused in different
parts of the program.
 It helps identify and address smaller issues early in the development process.
 It provides a clearer understanding of individual components and their functionality.

P.Madhubabu M.C.A & M.Tech 41


Introduction to Programming I-B.Tech, I-Semester
Q24)Explain about Time and space complexities of Algorithms
Space Complexity:
 Space complexity of an algorithm represents the amount of memory space needed the
algorithm in its life cycle.
 Space needed by an algorithm is equal to the sum of the following two components
 A fixed part that is a space required to store certain data and variables (i.e. simple
variables and constants, program size etc.), that are not dependent of the size of the
problem.
 A variable part is a space required by variables, whose size is totally dependent on the
size of the problem. For example, recursion stack space, dynamic memory allocation etc.
 Space complexity S(p) of any algorithm p is S(p) = A + Sp(I) Where A is treated as the
fixed part and S(I) is treated as the variable part of the algorithm which depends on
instance characteristic

Simple example that tries to explain the concept:


Algorithm:
SUM(P, Q)
Step 1 - START
Step 2 - R ← P + Q + 10
Step 3 - Stop
Here we have three variables P, Q and R and one constant. Hence S(p) = 1+3. Now space is
dependent on data types of given constant types and variables and it will be multiplied
accordingly.
Time Complexity:
 Time Complexity of an algorithm is the representation of the amount of time required by
the algorithm to execute to completion. Time requirements can be denoted or defined as
a numerical function t(N), where t(N) can be measured as the number of steps, provided
each step takes constant time.
 For example, in case of addition of two n-bit integers, N steps are taken. Consequently,
the total computational time is t(N) = c*n, where c is the time consumed for addition of
two bits. Here, we observe that t(N) grows linearly as input size increases.

P.Madhubabu M.C.A & M.Tech 42

You might also like