Question Bank SF (IBT- 102)
[SHORT QUESTION]
Q 1. What is Computer? Discuss the various characteristics of computer
Ans. Computer is an electronic device that stores, retrieves, and processes data, and can be
programmed with instructions A computer is composed of hardware and software, and can
exist in a variety of sizes and configurations. Computer system is a complete, working
computer. The computer system includes not only the computer, but also any software and
peripheral devices like monitors, keyboards, mice, printers, scanners, etc, that are necessary
to make the computer function. Every computer system, for example, requires an operating
system.
Q 2. What are the different characteristics of computers?
Ans. Characteristics of Computer: The important characteristics of computer include the
speed, accuracy, diligence, versatility, reliability and memory etc.
1. Speed: Computers are very fast. It takes only few seconds for calculations
We take hours to complete. They can process millions of instructions per second,
2. Accuracy: Computers are accurate. They do not make mistakes in calculations.
The probability ofcompJter error iS quite small and often traceable to faulty data.
Computer can perform all kinds of complex calculations accurately.
3. Elegance: A computer is free from tiredness, lack of concentration, fatigue, It can
work far hours without, creating any error.
4. Versatility It means the capacity to perform completely different type of work. You
may use your computer to prepare payroll slips.
5. Reliability Computer systems are widely accepted due to their exceptional reliability.
6. No IQ Computer is a dumb machine and it cannot do any work without instruction
from the user. It performs the instructions at tremendous speed and with accuracy.
7. No Feeling it does not have feelings or emotion, taste, knowledge and experience.
Thus it does not get tired even after long hours of work. It does not distinguish between users.
8. Storage the Computer has an inbuilt memory where it can store a large amount of data.
9. Power of Remembering Computer has the power ‘of storing any amount of information
or data.
Q3. What do you mean by data and information give difference between data and
information? Give the various features of information.
Ans. Data A collection of facts, concepts or instructions ar celled data, or a collection of
facts from which conclusions may be drawn. The different forms of data include the
alphanumeric, text, image data and audio data etc. The alphanumeric data composect of
alphabetic and numerals and other characters that describe business transactions, events,
entities. The text data are sentences and paragraphs used in written communications. The
Image data consists of graphics, shapes and figures and audio data refers to human voice and
other sounds.
Information: It is the organized or processed data. Or it is organized data that has been
arranged for better comprehension or understanding. In other words we can say that
Information is data that have been organized so that they have meaning and v)ue to the
recipient. What is one person’s information can become another person’s data.
Q 4. What are the different types of software?
Ans. Practical computer systems divide software into three major classes: system software,
programming software and application software, although the distinction is arbitrary, and
often blurred.
System software helps run the computer hardware and computer system. It includes operating
systems, device drivers, diagnostic tools, servers, wirdOwing systems, utilities and more. The
purpose of systems software is to insulate the applications programmer as much as possible
from the details of the particular computer complex being used, especially memory and other
hardware features, and such accessory devices as communications, printers, readers, disp)ays,
keyboards, etc, Programming software usually provides tools to assist a programmer in
writing computer programs and software using different programming languages in a more
convenient way. The tools include text editors, compilers, interpreters, linkers, debuggers,
and so on An Integrated development environment (IDE) merges those tools into a software
bundle, and a programmer may not need to type multiple commands for compiling,
interpreter, debugging, tracing, and etc., V because the IDE usually has an advanced
graphical user interface, or GUI.
Application software allows end users to accomplish one or more specific (minicomputer
related) tasks. Typical applications include industrial automation, business software,
educational software, medical software, databases, and computer games.
Businesses are probably the biggest users of application software, but almost every field
of human activity now uses some form of application software. It is used to automate all sorts
of functions.
Q6. What are the various application software?
Ans. Application software the mostly wide used are such application software packages:
• Text processing software,
• Graphical software,
• Electronic spreadsheets,
• Data base management systems,
• Expert systems,
• Computer aided design and engineering systems,
• Mathematical, statistical, simulation packages,
• Telecommunication software,
• Integrated common use packages,
• Packages expanding system software possibilities.
Q7. What is ROM? Why it is called non volatile memory?
Ans. ROM is read only memory. In this memory information is permanently stored. The
information from the memory can only be read and it is not possible to write fresh
information into it. That is why it is called ROM. Information on it is not lost when supply is
switched off. That is why it is called non-volatile memory.
Q8. What is CD-RW?
Ans. CD-RW stands for compact Disk Rewritable. CD-RW is memory storage device which
can store any type of data like file, audio files, video file or music files etc. Because this
device is Rewritable it means once we burn data in this CD it does not mean we can’t write
data again in this. We can reburn that CD and overwrite data upon old data.
Q 9. Define giving full forms of PROM, EPROM and EEPROM
Ans. PROM (Programmable read only memory) Creating a ROM chip from scratch is time
consuming and expensive process. For this reason, PROM was developed, which can be
programmed Once a PROM has been programmed, its contents can never be changed.
EPROM — (Erasable programmable read only memory) An EPROM can be erased and
reprogrammed repeatedly. It can be erased by simply exposing the device to a strong source
of ultraviolet light for a certain amount of time.
EEPROM (Electrically erasable programmable ROM) this type of ROM can be erased by an
electrical charge and then written to by using slightly higher than normal voltage.
Q 10. What is meant by PC memory?
Ans. Computers are used to perform various tasks in various fields; Computer requires
memory to process the data and to store the output. Memory refers to the electronic holding
place, for instructions and data where the computer microprocessor can reach quickly. Some
data will required instantaneously while other may not be needed for extended periods CPU
requires memory to handle the inter data results and to store the final Output Memory can be
classified in two ways. Primary and Secondary.
Q11. Why do we need Operating System?
Ans. Operating system is a collection of system. The operating system along with hardware
application and other system software and users constitute a computer system. It is most
important part of any computer system. It acts as an intermediary between a user and the
computer hardware. The operating system has two objectives. Firstly an operating system
controls the computer hardware. The second objective is to provide an interactive interface to
the user and interpret commands so that it can communicate with the hardware.
Q12. Why RAM is called volatile memory?
Ans. RAM is called volatile memory because when the power goes off, the cOntents of RAM
get erased. Random Access Memory (RAM) may be classified as Dynamic and Static.
Dynamic RAM consists of a transistor and capacitor that is capable of storing an electric
charge. Since the charge on capacitors tends to leak off, provision is made to penodically
refresh the storage charge. Thus, dynamic RAM provides volatile storage.
Static RAM is also volatile but as long as they are supplied with power, they need no special
regenerator circuits to retain the stored data. Static RAM consists of flip- flops. A flip flop is
a binary cell capable of storing one bit of information.
Q 13. Differentiate between Microfilm and microfiche?
Ans. Microfilm is used to record computer output information as microscopic fumed images.
The information that can be printed on a page of paper can be. reduced in size 48 or more
times and recorded on a sheet or roll of microfilm A 4-by-6 inch sheet of film is called
Microfiche A typical microfiche reproduces up to 270 page-sized images
Q 14. What is Cache Memory?
Ans Cache memory is a high speed semiconductor memory in-built into central processing
unit. It contains programs, instructions or data that is frequently used. It enables the computer
to operate at faster speed.
Q 15 Differentiate Control bus, data bus and address bus.
Ans. The physical connections that carry contr information between the Cpu and other
devices Within the computer is balled contro bus. The data bus carries actual data that is
being processed, the control bus carries sighals that report the status of various devices. For
example, one line of the bus is used to indicate whether the CPU is currently reading from or
writing to main memory. Whereas theaddress bus is used to carry addresses of memorV
locations or I/O ports.
Q16. What are the features of Von-Neuman Machine?
Ans. Von-Neumann machine is an Early Computer which includes 3 components:
CPU, hard disk and RAM. The machine stores instructions as binary values and executes the
instructions sequentially in the processor fetches the instructions one at a time and processes
them.
Q17 How many memory chips of 1K x 8bit are required to construct 8K x 8 bit
memory?
Ans. 8 memory chips of 1K x 8 bit are required to construct 8K x 8 bit memory.
Q 18. CD is a random or a sequential storage device.
Ans. CD is random access device. The data, is permanent and can be read any number of
times.
Q 19. What is an algorithm?
Ans. An algorithm is a procedure for accomplishing some task which, given an initial state,
will terminate in a defined end-state. The computational complexity and efficient
implementation of the algorithm are. important in computing, and this depends on suitable
data structures.
Q 20. What is primary memory?
Ans. The primary storage or main memory is a part of microcomputer that holds data for
processing, instructions for processing the data and the information. The memory identifies
data storage that comes in the form of chips. There are two types of memory.
1. RAM-Random access memory
2. ROM-Read only memory.
Q 21. What is a random file?
Ans. A random file is one in which records or data is accessed randomly. It is useful when
there are large number of records in a file and only few records have to be updated in a
random other; this saves lot of access time of a record. To access random file the following
functions are used
(a) seekp ( ) or seekg ( )
(b) fellg ( ) or fellp ( )
Q 22. What is the use of ROM in a PC?
Ans. ROM stands for Read Only Memory which holds instructions for starting up• the
computer. The computer loads data from read-only memory (ROM) and performs a power-on
self-test (POST) to make sure all the major components are functioning properly. The
computer loads the basic input/output system (BIOS) from ROM. The BIOS provides the
most basic information about storage devices, boot sequence, security, Plug and Play
capabilitFes and a few other items. Unlike the main memory (RAM), ROM retains contents
even when the computer is turned off. ROM is referred to as being non volatile.
Q23. What is the function of control unit?
Ans. The functions of control unit are as follows
(I) The control unit tells the test of the computer system how to carry out a program’s
instructions.
(ii) It dIrects the movement of electronic signals between memory - which temporarily
holds data, instructons and processed information -. and the ALU.
(iii) It also directs these control signals between the Cpu and input/output devices.
Q24. What is the difference between RAM and ROM?
Ans. RAM stands for Random Access Memory. It is a volatile memory i.e. it needs
constant refreshal and stores the data temporarily. It is made up of capacitors and flip-flops
and it allows reading as well writing of data. It has fast data retrieval speed as compared to
ROM.
ROM stands for Read Only Memory. It is a non-volatile memory and store data permanently.
It is made up of diodes and allows ohly reading of data. It is a firmware that holds the boot
sequence of computer system.
Q25. What is the difference between Primary and Secondary Memory?
Q 26. Distinguish between Semi Conductor and Magnetic Memories.
Q 27 What are the major differences between primary and secondary
memory of a computer?
Ans.
10 Marks Questions
Q 1. What are the various components of computer? Explain with the help of block
diagram.
OR
With a neat sketch explain the basic structure of computer
Ans The internal Architectural Design of computers differs from one system model to
another. However, the basic organization remains the same for all computer systems. All
computer systems perform the following five basic operations inputting, Processing,
Outputting and Controlling
In the above figure, the solid lines are used to indicate the flow of instructions and data,
and the dotted lines represent the control exercised by the; control unit.
The five major functional units correspond to the five basic operations performed by all
computer systems. The functions of these units are as below Input unit: Input unit links the
External Environment with the computer system i.e. it handles the process of entering the
data and instructions into the computer system. Various Input Devices can he used for
enterthg the data. Various Input Devices that re commonly used are keyboard, Mouse, Card
Reader, Scanners. AU the Inpyt Devices mus.t provide cQmputerwith data thataretransferred
into binary codes that the primary memory of computer is designed to Accept. This
transformation Is accomplished by units called Input.
Interfaces : Thus, the Input Unit performs the following functions
1. It accepts the data and instructions from outside world.
2. It converts these instructions and data into computer Acceptable form.
3, It supplies the converted data and instructions to computer system for further
Processing.
Output unit: The job of Output Unit is just the reverse of that of input unit i.e. it links the
computer with External Environment. It supplies the information and results of computation
to the outside world. As the computer work with binary codes, the results. produced are also
in binary form. Thus, the results must be converted into human understandable form before
supplying to the outside world. This task is accomplished by unit called Output Interfaces.
Thus, the main functions of Output Unit are
1. It accepts the results produced by computer which are in coded form.
2. It converts those coded results into human Acceptable form.
3. it supplies the converted result to the outside world.
Storage Unit: Storage unit or Primary/main storage of a computer system is designed to
store data and instructions so that they are available for processing as and when required; It
provides space for storing data and instructions, space for intermediate results and also space
for final results.
Thus, the main functions of storage unit are:
1. To hold all data to be processed and instructions required for processing.
2. To store intermediate results of processing.
3. To store final results of processing before these resu!ts are released to output device.
Central Processing Unit (CPU) : The control unit and ALU of computer system rare
jointly known as Central Processinq Unit (CPU). PU is the brain of any computer isystem:
All major calculations and comparison are made inside CPU and CPU is also responsible for
activating and controlling the operations of other units of computer The two units of CPU —
Control unit (CU) and Arithmetic Logic Unit (ALU) are described below:
(i) Control Unit (CU) : The control unit acts a a Central Nervous system for the other
components of the compute. Although it does not perform any actual Processing on the data
but by selecting interpreting and seeing to the execution of program instructions it maintains
the order and directs the operation of the entire system.
Thus, the functions of control unit are as follows:
1. It managers and coordinates the entire computer system.
2. program stored in main memory
3. It interprets/decodes the instructions
4. It issues signals that causes other Units of the system to perform their
(ii) Arithmetic Logic Unit (ALU) : ALU àf a computer is the place where Execution of
instructions takes place during the processing operation. The data instructions that are stored
in primary memory are transferred as and when needed the ALU where processing takes
place. Intermediate results generated in ALU temporarily transferred back to primary
memory. Thus Data may move between primary memory and ALU many times before
processing is over. The type and number of Arithmetic and Logic operations that a computer
can perform depends on engineering design ALU. However, all ALU’S are designed to
perform four basic arithmetic operations — subtract, multiply and divide and logic
Operations such as less than, equal to or greater than. Thus functions of ALU are
(1).It accepts data and decoded instructions from main’memory and control
(2).It performs Arithmetic and Logical operations on data according to instructions.
(3).It returns the final results tomain memory for storage.
Q 2. What are the various secondary storage devices? Explain giving examples.
Ans. Secondary storage device facilitates storing of information and programs permanently.
The information in a secondary storage device can be accessed depending upon how the
information is stored on the device. Primarily there are two methods accessing data from the
secondary storage devices.
1. Sequential
2. Direct
Based on access, secondary storage device can be classified as shown:
the form of tiny segments of magnetized and de-magnetized portion on the surface of the
material. Magnetized portion of the surface refers to the bit value ‘1’ where as demagnetized
portion refers to the bit value 0.
Magnetic disk: Magnetic disk is the widely used popular storage medium for direct
access secondary storage. They offer high storage capacity, reliability and have capability to
access the stored data directly. It consists of plastic/metal circular plate which is coated with
magnetic oxide layer. Data is represented as magnetic spot on disk. There are three types .of
Magnetic Disk, Floppy disk, Hard disk and Zip disk.
Optical disk: Optical disk is a flat, circular plastic disk coated with material on hich bits
may be stored in the form of highly reflective areas and significantly less reflective areas
from which the stored data may be read when illuminated with a narrow beam source such as
laser diode. It is of two types CD-ROM and .WROM of Magneto optical stored device : The
magnetic. Optical system includes basic principles of both magnetic and optical storage
system. This system writes magnetically and read optically.
Q 3. Discuss in detail the chief characteristics, capabilities and evolutions of computers
aid what are the motivating forces behind the development of computers.
Ans. Characteristics of computers:
1. Speed : A computer is very fast device. It can perform in a few seconds the mount of
work that human being can do in entire year. if he worked day and flight andY id nothing
else.
2. Accuracy : The accuracy of the computer is consistently high and the degrees f
accuracy of a particular computer depend upon-its design. But for particulai computer, lach
and every calculation is performed with the same accuracy
3. Diligence: Unlike human being, a computeris free from monotony; tired less lack of
concentration etc. and hence can work for hours together without creating any error and
without grutnbling.
4. Power of remembering : A computer can store and recall any amount of information
because of its secondary storage capacity. 1
5. Versatility : A computer is capable of performing almost any task provided that task
can be reduced to a series of logical steps.
Evolution of computers The computer generations are:
(i) First Generation Computers: First generation Computers used Thermionic Valves
and programming was done in machine languages. The period of the first generation
computer was 1951—1958. All the computers were of very big sizes and programming was
very difficult. The input and output devices used were punched card readers and card
punches. These were very slow computers. Electronic Numerical Integrator and Calculator
was the beginning of first generation computers. It was based upon decimal number system
rather than binary number system. The limitations of first generation computers were:
(a) High Power Consumption
(b) Very big in size.
(c) Slow speed
(d) Limited programming Capability.
(ii) Second Generation Computers : These computers were made using transistors. In
these new powerful computers machine language was replaced by the easier to programmed
assembly language. These computers used batch processing modes. Punched cards or
magnetic tape were used for input media. These computers consumed less power, small in
size and were faster and more reliable. These computers used binary number system. The
basic limitation of 2nd generation computers was that these machines were more expensive.
The period of second generation computers was from 1959—1964.
(iii) Third Generation Computers : Transistors had been reduced in size so that
hundreds of them could be embedded in small pieces Silicon transistors were used instead of
Germanium. These computers were based upon the concept of integrated transistor circuit
called (IC). Third generation computers are smaller, faster, cheaper and even more reliable
than second generation. Punch cards, magnetic tape and magnetic disk were used as
input/output media The period of generation was from 1965 to 1970. The magnetic core
semiconductor memory were used as primary storage for computer.
(iv) Fourth Generation Computers : In these computers, the control processor unit was
embedded into a single chip which was made possible due to technique of large scale
integration LSI. This increased the overall speed of computation and reduced its size. Micro
computers came into existence into 1974 due development of micro-processor chips in 1971
by INTEL of U.S.A.
(v) Fifth Generation Computers : These computers are yet to come in t market. These
computers will be based upon the concept of Artificial intelligence. These computers will be
having thinking power, pattern recognition and will be having computational logics. These
computers will be totally different from the first four generations; these machines will be
controlled by voice of human beings. These computers are under development in Japan, USA
and some European countries. These computers are so called knowledge information
processing systems. The misstating forces behind the development of computers are the
speed, efficiency, size, memory and versatility of job performing.
Q 4. What are the various output devices of a computer?
Ans. Output is the result of processes that are done on the computer. An output device
receives information from the computer and translates it form machine language to a form
that humans can read or so that another machine can read the information. Various output
devices include printer, monitor, speaker and plotter.
1. Printer: Printers are devices that print text or illustrations on paper. There are. many
different types of printers. Two categories are impact and non-impact.
Impact printers transfer the image onto paper through a printing mechanism that strikes
the paper, ribbon and character together. Most impact printers use a continuous- form paper,
which means the paper is connected together to produce a continuous flow through the
printer. Examples of impact printers are Dot Matrix printers, and Band and Chain Printers.
Non-impact printing means that printing occurs without having a mechanism strike the
paper. Ink can be sprayed against the paper or heat and pressure are used to fuse a fine black
powder into the shape of a character. Examples of non-impact printers are Ink-Jet printers,
Laser printers, Page printers and Thermal printers.
Some important features of the different printers are speed, graphics capability,1 fonts,
and color. Speed is measured in characters per second or pages per minute. The speed of
printers varies widely. Dot-matrix printers can print upto 500 cps, and laser printers range
from about 4 to 20 text pages per minute. All three of these printers are able to print both text
and graphics. Dot matrix printers are limited to one or a few fonts. In contrast, laser and ink-
jet printers are capable of printing an almost unlimited. variety of fonts.
2. Monitor : The monitor is primarily an output device, It converts signals from the
computer into a visual display that is the result of orocessino
It can be thought of as a high resolution TV set. The monitor c display will be color, black
and white, or include graphical object text and images converted to output from the video
adapter. i ne viaeo aoapter i expansion card that plugs into the motherboard. The adapter
changes the instruct. from the central processing unit into a way that the monitor can
understand it.
3. Speaker : An important feature of the sound card and speakers is the type of interface
found on the computers. One important feature is the MIDI or the Musical Instrumental
Digital Interface. MIDI is a set of rules that allow synthesizers, musical instruments and
computers to exchange data. This is an important feature because if a sound cards supports
MID!, then the computer can play the sounds found in games and CD-ROMS.
Two ways sound cards can produce MIDI sounds
1. Wave table — It uses the actual recordings of musical instruments.
2. FM — It imitates the sounds of musical instruments.
4. Plotter: An output device that produces a graphical representation by drawing on
paper, as with one or more attached pens. Plotters can be interfaced serially or parallel. Large
plotters are driven using an Ethernet connection and the smaller ones can be driven using RS-
232 interface. There are two types of plotters. One is called drum plotter and other a flat bed
plotter. In flat bed plotter pen moves across the paper in two dimensions X and Y. While in
drum plotter pen moves only in one dimension.
Q 5. Explain in detail different types of memories available in a computer system
OR
What are the various types of memories of a computer? Explain the usage of each
type of memory.
Ans. There are several different types of memory
1. RAM (Random Access Memory)
2. ROM (Read Only Memory)
3. PROM (Programmable Read Only Memory)
4. EPROM (Erasable Programmable Read Only Memory)
5. EEPROM (Electrically Erasable Programmable Read Only Memory)
1. RAM : RAM refers to read and write memory; that is, you can, both write data into
RAM and read data from RAM.
There are two types of RAM
(a) Dynamic RAM
(b) Static RAM.
Dynamic RAM needs to be refreshed thousands of times per second. Static RAM needs to be
refreshed less often, which makes it faster; but it is more expensive than dynamic RAM. Both
types of RAM are volatile, meaning that they lose their contents when the power is turned
off. In common usage, the term RAM is synonymous with main memory, the memory
available to programs. For example, a computer with 8 MB RAM has approximately 1
million bytes of memory that programs can use. In fact, both types of memory ROM and
RAM allow random access.
2. ROM : Read only memory is a computer memory on which data has been pre
recorded. Once data has been written onto a ROM chip, it cannot be removed and can only be
read. Unlike the main memory (RAM), ROM retains contents even when the computer is
turned off. ROM is referred to as being non volatile whereas RAM is volatile.
Most personal computers contain a small amount of ROM that stores critical programs such
as the programs that boots the computer. In addition, ROMs are used extensively in
calculators and peripheral devices such as laser printers. A variation of a ROM is the PROM.
PROMsare manufactured as blank chips on which datacan be written.
3. PROM : A PROM is a memory chip on which data can be written only once. Once a
program has been written on to a PROM, it remains there forever. Unlike the mm memory,
PROMs retain their contents when the computer is turned off. The difference between a
PROM and a ROM is that a PROM is manufactured as blank memory, whereas a ROM is
programmed during the manufacturing process. To write data onto a PROM chip, you need a
special device called a PROM programmer or a PROM byrner. The process of programming
a PROM is sometimes called burning the PROM.
4. EPROM : EPROM is a special type of memory that retains its contents until it is
exposed to ultraviolet light. The ultraviolet light clears its contents, making it possible to
reprogram the memory. An EPROM differs from a PROM in that a PROM can be written to
only once and cannot be erased. EPROMs are used widely in personal computers because
they enable the manufacturer to change the contents of the PROM before the computer is
actually shipped. This means that bugs can be removed and new versions installed shortly
before delivery.
5. EEPROM : EEPROM is a special type of PROM that can be erased by exposing it to
an electrical charge. Like other types of PROM, EEPROM retains its contents even when the
power is turned off. Also like all other types of ROM, EEPROM is not as fast as RAM.
EEPROM is similar to flash memory. The principle difference is that EEPROM requires data
to be written or erased one byte at a time whereas flash memory allows data to be written or
erased in blocks. This makes flash memory faster.
6. Flash memory: Flash memory is a special type of EEPROM that can be erased and
reprogrammed in blocks instead of one byte at a time. Many modern PCs have their BIOS
stored on a flash memory chip so that it can easily be updated if necessary. Such a BIOS is
sometimes called a flash BIOS, flash memory is also popular in moderns because it enables
the modem manufacturer to support new protocols as they become standardized.
Q 6. How does an instruction get executed on a computer? Explain with the help of a
block diagram.
Ans. A computer is a complex system consisting of many different components. But at
the heart of the computer is a single component.that does the actual computing. This is the
Central Processing Unit or CPU. In a modern desktop computer; the CPU is a single “chip”
on the order of one square inch in size. The job of the CPU is to execute programs.
A program is simply a list of unambiguous instructions meant to be lolloweci
mechanically by a computer. A computer is built to carry out instructions that are written in a
very simple type of language called machine language. Each typeof computer has its own
machine language, and it can directly execute a program onIy if it is expressed in that
language.
When the CPU executes a program, that program is stored in the computer’s main
memory. In addition to the program, memory can also hold data that is being used or
processed by the program. Main memory consists of a sequence of locations.
These locations are numbered, and the sequence number of a location is called its address.
An address provides a way of picking out one particular piece of information from among the
millions stored in memory.
When the CPU needs to access the program instruction or data in a particular location, it
sends the address of that information as a signal to the memory ; the memory responds by
sending back the data contained in the specified location. The CPU “decodes” the instruction
to figure out what to do. The CPU “executes” the operation specified by the instruction on
data. The CPU can also store information in memory by specifying the information to be
stored and the address of the location where it is to be stored.
The CPU spends almost all its time fetching instructions from memory and executing
them. A computer system consisting of many devices e.g. monitor, printer, hard disk; scanner
is typically organized by connecting those devices to one or more buses. A bus is a set of
wires that carry various sorts of information between the devices connected to those wires.
The wires carry data, addresses and control signals.
An address directs the data to a particular device and perhaps to a particular register or
location within that device. Control signals can be used, for example, by one device to alert
another that data is available for it on the data bus. A fairly simple computersystem might be
organized like this:
Now, devices such as keyboard, mouse and network interface can produce input that
needs to be processed by the CPU. CPU keeps checking for incoming data over and
whenever it finds data; it processes it. This method is called polling, since the CPU polls the
input device continually to see whether they have any input data to report. Unfortunately,
although polling is very simple, it is also very inefficient. The CPU can waste an awful lot of
time just waiting for input.
To avoid this inefficiency, interrupts are often used instead of polling. An interrupt is a
signal sent by another device to the CPU. The CPU responds to an interrupt signal by putting
aside whatever it is doing in order to respond to the interrupt. Once it has handled the
interrupt, it returns to what it was doing before the interrupt occurred.
Q 7. Describe various functional components of the computer.
Ans, Computer system comprises of following four components
1. Central Processing Unit (CPU)
2. input Unit
3. Output Unit
4. Storage Unit
1. Central Processing Unit: It is administrative section of computer system. It interprets
coordinates the operations and supervises the instruction. CPU works with data in discrete
form that is either 1 or 0. The circuits necessary to create a CPU for personal computer are
fabricated on microprocessor. The CPU itself has three parts.
(i) Arithmetic logic unit (ALU) This unit performs Arithmetic and logic operation on the
stored numbers.
(ii) Control unit This unit check the correctness of sequence of operation.
(iii) Memory unit: This unit hold the intermediate result during the course of calculation
and provide the data as and when required. This internal storage device is called primary
memory. -
2. Input, Output and Storage Unit: Input unit accepts instructions and data from the
user and communicate them to computer. The basic task of this unit is to gather the data and
convert into the form that computer understand. Input devices are keyboard, mouse, and light
pen and so on,
Just as humans. Communicate with computer through input device. The computer
communicates with human being using output-device. Output device are printers, monitor
and plotter.
In addition to these parts computer also employs secondary storage device which are
extensively used for storing data or instructions. Some common storage devices are floppy
disk and tape driver.
Q 8. What are the various classification of computer?
Ans. Classification of computers: In general, classification of computers on the basis of
Electronics, Storage capacity & Usage.
Classification on the basis of their electronics
Analog Computers: These computers operate on inputs of continuously varying
electrical voltage. They represent numbers by a physical quantity; i.e., they assign numeric
values by physically measuring some actual property such as length of an object, angle or
amount of voltage passing through a point in an electric circuit, they derive all their data from
some form of measurement. Though these are effective for some applications, still
representing numbers is a limitation of the analog computer. The accuracy of the data used in
an analog computer is directly related to the precision in its measurement. Analog computers
are used mainly in scientific, design and production environment. Each one has to be
constructed to do a specific job and will respond very quickly to the changes in the
measurement inputs.
Digital Computers: These computers represent data as numbers or separate units. The
digital computer can represent data accurately using as many positions and numbers a
required. Adding machines and calculators are common examples of devices based on
principles of digital computers. Mathematical expressions represented as binary digits (0 and
1) and all mathematical operations are done using these digits at a very high rate. It means
that the computer operates on electrical inputs that have only two states, ON and OFF. They
find use in commercial and control systems. In today’s computer age when we say the word
“computer’ it mostly refers to a binary electronic digital computer.
Hybrid Computers: These computers are based on the best features of analog and digital
computers. They are having the speed of analog computers and the accuracy of digital
computers. These are specifically used in the situation in which input data derived from
measurements is converted into digits and processed by computer. These control national
defense and passenger flight radar. They operate by counting as well as measuring. In other
words, the output can be either in the form of numbers or required units of measurement. For
example, an analog device measures patient’s heartbeat (ECG). These measures will be
converted into digital form and a digital device checks for any abnormality. Further, we can
also input digital data like your marks, number of employees; salaries etc, and get digital
results. Another example is modem, which converts digital signals into analog, carry it along
the line and at the receiving end’ again it changes the signal into digital form. This is called
digital - to - analog conversion. The circuit that performs this function is a digital - to - analog
converters (DAC). The above two processes of conversion (digital - to analog and analog - to
- digital) are opposite of each other.
In most cases, if an ADC is placed in a communication circuit after a DAC then the digital
signal’ output is identical to the digital signal input.
Similarly, in most instances when a DAC is placed after an ADC, then the analog signal
output is identical to the analog signal input.
In digital computers the entire information appears as long strings of zeros and ones. They
have no apparent meaning to a human observer. But while coding is done by using DAC,
then meaningful output is obtained. Both the DAC and ADC are of great significance in some
applications of digital signal processing (DSP). The intelligibility of one signal can often be
improved by converting the signal input from one form to the other by using one converter
and back to the same form by using the other kind of converter as explained above.
Classification of computers on the basis of memory size and storage capacity
Supercomputers (256 MB onwards) : Supercomputers are basically designed complex
scientific applications. Therefore, there is a substantial increase in the speed of computation.
The cycle time on a typical supercomputer Will be as low as 4 nanoseconds. In 1994
scientists received an alert signal by a super computer about a collision between a comet awls
Jupiter. The first supercomputer was built in 1960s for the U.S department of defense. This
computer was designed to be the world’s fastest and most powerful computer of that time.
The great speed of supercomputers is obtained from the use of multiprocessors. Each
processor is assigned different task thereby increasing the speed of supercomputer. The speed
of modern supercomputers is measured in nanoseconds and gigabits A nanosecond is 1
billionth of a second. A gigabits is 1 billion floating point arithmetic operations per second.
Supercomputers can perform 128 gigaflops. Thinking Machines have produced a super
computer called the Connection Machine. It uses over 64, 000 processors. The normal range
of supercomputers is from $2 million to $20 million.
The main features of supercomputers can be summarized as below
(i) are the fastest, largest and most expensive computers.
(ii) - use processing power to solve a few computer intensive task.
(iii) - can process I trillion instructions per second.
(iv) - 5 million times faster than first computer ENIAC.
(v) - have parallel processor.
(vi) - can perform simultaneously many computations whereas a conventional computer uses
a series of sequential steps.
- are often used for complex scientific applications like weather forecasting, problems
concerning ballistic missiles, nuclear reactor designs, modeling large linear programming,
seismic data processing etc.
(viii) - are very costly (millions of dollars)
(ix) - the aerospace, automotive, chemical, electronics, petroleum industries use
supercomputers extensively. Cray’s XMP 1, 2, 3, CDC’s 205, ETA GF 10, NEC’s SX - 2,
Fujitsu’s VP-200 and 400 and Hitachi’s S - 810/20 are some of the most popular
supercomputers. Out of these ETA - 10 is the fastest supercomputer he CRAY T3E
supercomputer, configurable with 6 to 2048 processors, provides the computing power to
tackle the world’s most challenging- computing problems. ILLIAC - IV was the first
supercomputer. 64 different calculations could be made at a time i.e., it is equivalent to 64
different computers. It can execute instructions at the rate of 300 million per second.
Mainframe (80 - 128 MB onwards) : The earliest computers were called mainframes due to
their enormous size. The term is still in use for the large computers of today but the modals of
mainframes are far more powerful. The storage capacity of these computers very high and
data can be processed very quickly. Big companies banks, government departments use
mainframes. IBM, the giant of the computer industry, captured the mainframe market in late
1950s and made its name fortune manufacturing mainframe computer systems. The typical
mainframe computers occupy much of a large room. These computers require controlled
temperature and humidity conditions.
Many modern mainframes have multi-processing capabilities; however, they are limited to 8
processors. The speed of mainframes is less than that of supercomputers (1/1000th that of
supercomputers).A mainframe computer system is usually composed of several computers in
addition to the mainframe or host processor. The host processor is responsible for controlling
the other processors, all the peripheral devices and the mathematical operations. A front-end
processor handles communications to and from all the remote terminals connected to the
system. A back-end processor handles data retrieval operations. Multiple operations can be
performed more efficiently and effectively with such a mainframe computer. Mainframe
computer systems are powerful enough to support several hundred users simultaneously at
remote terminals. This capability to process many programs concurrently for multiple users is
known multiprogramming .IBM’s 308X - 508 series, IBM 3090, 4300, 4381, DEC - 1090,
10, 20, Cyber’s - 170 are the examples.
The main features of mainframe computers can be summarized as below
(i) - are large, fast and expensive.
(ii) - provide centralized data storage, processing and management.
(iii) - are used by business, industry and government.
(iv) - use terminals to send and receive user requests quickly.
(v) - can handle several hundred requests quickly.
(vi) - often have more than on CPU.
Mini computers (20 MB onwards) : These computers are at least 5 times faster than
microcomputers having CPU speed of approximately 500 instructions per second. Such
systems are characterized by their main memory size. This may be 250 KB to 12 MB, word
length of 16/32 bits and are designed for 4 to 8 users in timesharing odes. For example,
DEC’s Vax series 8200 and 8300 are major minicomputers. The “age of the mini” started in
the late 1960s. Before Digital Equipment Corporation (DEC) released the first DEC PDP-8
minicomputer in 1968, most medium sized organizations were priced out of the computer
market because they could not afford mainframe computers (Price ranging from $100,000 to
$2,000,000). The DEC computer cost around $50,000. It was a considerable saving.
Minicomputers have many uses in business and commerce and can be used for as such
applications such as payroll, noticing and stack control, reservation and banking. The major
difference between mainframes and minicomputers in scale. Minicomputers can perform the
same types of tasks but are a little slower. They have slightly less storage than mainframes.
Q 9. Write a short note on different types of computer.
Ans.Personal computers : A personal computer is a computer that can perform all of
input, processing, Output and storage activities by itself by itself. A personal computer
contains a processor, memory, and one or more input, output, and storage devices.
Two popular types of personal computers are the PC and the Apple. The term, PC-
compatible, Two types of personal computers are desktop computers and notebook
computers.
Desktop Computers : A desktop computer is designed so the system unit, input devices
output devices, and any other device fit entirety on or under a desk or table. Some desktop
computers are powerful enough to function as a server on a network. These -High-end
compute cost much more than the basic desktop computer. Another expensive, powerful
desktop computer is the workstation, which Fields such as engineering, desktop publishing,
and graphic require the power of a workstation. An arch requires uses a workstation to view
and create ‘imps. A graphic artist uses a workstation to create computer-animation special
effects for full-length motion pictures and video games.
Mobile computers and mobiles devices A mobile computer is a personal computer that you
can carry from place to place. Similarly a mobile device is a computing device small enough
to hold in your hand. The following sections discuss the notebook computers and widely use
mobile devices.
Notebook Computers: A notebook computer, also called a laptop computer, is a portable,
personal computer small enough to fit on your lap. Today’s Notebook computers are thin and
lightweight, yet they can be as powerful as the average desktop computers generally are more
expensive than desktop computers with equal capabilities.
Tablet. PC: Resembling letter-sized slate, the Tablet PC is a special type of notebook
computer that we it, to write on the screen using a digital pen. With a digital pent, users write
on the screen or issue instructions to the Tablet PC, You can attach a key board to these
computers. Most Tablet PC applications run with or without a keyboard. Tablet PC’s
also. Tablet PCs are useful especially for taking note in lectures, at meetings, conferences,
and other forums where the standard notebook Computer is not practical. Three popular types
of mobile devices are handheld computers, PDAS, and smart phones. Some combination
mobile devices also are available, for example, a PDA/smart phone
Handheld computer: A handheld computer is a computer small enough to fit in one
hand while you operate it with the other once hard which you operate with the other hand
Because of their reduces size, the screens on hand held computers are quite small. Some
handheld computers have a special keyboard. Such as meter readers and parcel delivery
people, whose jobs require them to move from place to place.
PDA: A PDA (personal digital assistant) provides personal organizer functions such as a
calendar. Appointment book, address book, calculator. And note pad. Most PDAs also offer a
variety of other application software such as, word sheet, personal r and games. Some even
include soft ware that enables users to read a book on the device’s screen.
Mobile Devices : You typically connect a mobile device to a personal computer to
exchange information between the computer and the mobile device. Users can check email
and access th Internet. The primary input device of a PDA is the stylus. A stylus looks like a
small ballpoint pen, but uses pressure Instead of lath to write and draw you prefer to type,
you can insert PDAS without keyboards into a special keyboard, Sorne PDAs also support
voice input. Smart phones: Offering the convenience of on handed operation, a smart phone
is a Web-enabled telephone. In addition to basic phone capabilities, a smart phone allows you
to send and access the Interact. Some higher- priced models have color screens and play
music,’
Q 10. Discuss the various application of computer in different fields of life.
Ans. A computer can be defined as an electronic data processing device, capable of
accepting data, applying a prescribed set of instructions to the data, and displaying in some
‘manner or form. Any configuration of the devices that are interconnected and are
programmed to operate as a computer system. The computer is said to have literally
revolutionized the .way one person does his job or a whole multinational organization
operates their businesses. Together with this reason and many more, computers are
considered more than just an essential piece of fancy equipment. Whether or not people now
anything about it, they invoke corrupters in everyday lives when they make a bank
withdrawal, buy groceries at the supermarket and even when they drive a car. Today, millions
of people are purchasing fully functional personal computers for individual reasons. In their
homes, people use various forms of computer technology for writing memos, for keeping
track of bank accounts, for communication with friends and associates, for accessing
knowledge, for purchasing goods and many other countless tasks.
It is binding fact that are computers are very productive, efficient and make our personal
and professional lives more rewarding. These ‘magical’ machines can do just’ about anything
imaginable, moreover they realty excel in certain areas. Below is the list of some of the
principal applications of the computer systems:
1. Businesses: Businessmen make bar graphs and pie charts from tedious figures to
convey information with far more impact than numbers alone can covey. Furthermore,
computers help businesses to predict their future sales, profits, costs etc. making companies
more accurate in their accounts. Computers may also play a vital rote in aiding thousands of
organizations to make judgmental and hard-provoking decisions concerning financial
problems and prospective trends.
2. Buildings : Architects use computer animated graphics to experiment with possible
exteriors and to give clients a visual walk-through of their proposed buildings The computers
provide architects a numerous amount of facilities to create different buildings with greater
accuracy, better designing and editing tools, and work done at the fastest speed possible.
Finally, a new kind of artist has emerged, one who uses computers to express his or her
creativity.
3. Education: Most good schools in the world have computers available for use in the
classroom. It has been proved that learning with computers has been more successful and this
is why numerous forms of new teaching methods have been introduced. This enhances the
knowledge of the student at a much faster pace than the old traditional methods. Likewise,
colleges and various universities have extended the use of computers as many educators
prefer the ‘learning by doing’ method.- an approach uniquely suited to the computer.
4. Retailing : Products from meats to magazines are packed with zebra-striped bar codes
that can be read by the computer scanners at supermarket checkout stands to determine prices
and help manage inventory, thus, a detailed receipt of the groceries can be made, which is
useful for both the customer and the retail store, especially for the stock control system. This
is referred as POS (Point of Sale) transaction where a precise account of all the stocks
available is recorded and manipulated.
5. Energy: Energy companies use computers to locate oil, coal, natural gas and uranium.
With the use of these technological machines, these companies can figure out the site of a
natural resource, its concentration and other related figures. Electric companies use
computers to monitor vast power networks. In addition, meter readers use hand held
computers to record how much energy is used each month in homes and offices.
6 Law Enforcement: Recent innovation in computerized law enforcement include
national fingerprint files, a national file o the mode of operation of serial killers, and
computer modeling of DNA, which can be used to match traces from an alleged criminal’s
body, such as blood at a crime scene. In addition, computers also contain complete databases
of all the names, pictures and information of such people who choose to break the law.
7. Transportation : Computers are used in cars to monitor fluid levels, temperatures and
electrical systems. Computers are also used to help run rapid transit systems, load
containerships and track railroads cars across the country. An important part is the ar control
traffic systems, where computers are used to control the flow of traffic between airplanes
which needs a lot of precision and accuracy to be dealt with.
8. Money: Computers speed up record keeping and allow banks to offer same-
dayservices and even do-it yourself banking over the phone and internet. Computers have
helped fuel the cashless economy, enabling the widespread use of credit cards, debit cards
and instantaneous credit checks by banks and retailers. There is also a level of greater
security when computers are involved in money transactions as there is a better chance of
detecting forged cheques and using credit/debit cards illegally etc.
9. Agriculture: Farmers use small computers to help with billing, crop information, and
cost per acre, feed combinations, and market price checks. Cattle ranchers can also use
computers for information about livestock breeding and performance.
10. Government: Among other tasks, the federal government uses computers to forecast
the weather, to manage parks and historical sites, to process immigrants, to produce social
security checks and to collect taxes. The most important use of the computer system in in this
field is perhaps the Army, the Air Force and the Navy. The computers have to be very
powerful and in order to be run they have to be very accurate and precise. E.g. in the use of
missiles and other likes, every nanosecond counts, which may save trillions of lives on this
planet. The government also uses computers in various simulations like the spread of
influenza in a particular locality.
11. The Home: People having a computer in the home justifies the fact that it is not only
useful and efficient, but it is also revered as a learning system. Personal computers are being
used for innumerous tasks nowadays, for example, to keep records, write letters and memos,
prepare budgets, produce presentations, draw pictures, publish newsletters and most
importantly - connect with other in the rest of plant earth.
12. Health and Medicine : Computers are helping immensely to monitor thee extremely
ill in the intensive care unit and provide cross-sectional views of the body. This eliminates the
need for hired nurses to watch the patient twenty-four hours a day, which is greatly tiring and
error prone. Doctors use computers to assist them in diagnosing certain diseases of the sort.
This type of computer is called the Expert System, which is basically a collection of
accumulated expertise in a specific area of field. Computers are now able to map, tn exquisite
detail, the structure of the human cold virus the first step towards the common cold.
Furthermore, computers are used greatly in managing patients, doctors, wards and medicine
records, as well as deal with making appointments, scheduling surgeries and other likes.
13. Manufacturing Industries : Computers have made their way towards jobs that were
unpleasant or too dangerous for humans to do, such as working hundreds of feet below the
earth or opening a package that might contain an explosive device. In other industries,
computers are used to control the production of resources very precisely. All robots and
machinery are now controlled by various computers, making the production process faster
and cheaper. All the stages of manufacturing, from designing to production, can be done with
the use of computer technology with greater diversity.
14. The Human connection : The computers have evolved in such prosperity that it is
now able to assist or aid with humans who are disabled - both physically and mentally. The
handicapped are now able to express their missing sense with the aid of computer technology.
For example, a deaf and dumb person is able o communicate extensively with other people by
using a specially designed computer system. This gives the disabled a chance to have out life
and gradually catch up the other fortunate people living on earth.
15. Scientific Research : This is very important for mankind and. with the development
of computers; scientific research has propelled towards the better a great deal. Because of
high-speed characteristics of computer systems, researchers can simulate environments,
emulate physical characteristics and aHow scientists to proof of their theories in a-cost-
effective manner. Also many test lab animals are spared since computers have t&cen over
their roles in extensive research.
16. Communication with the World : The computes are most popular for their uses to
connect with others on the World Wide Web, Therefore, communication between two or
more parties is possible which is relatively cheap considering the old: fashioned methods.
Emailing, teleconferencing and the use of voice messages are very fast, effective and
surprisingly cheaper as well, When connected to the Internet, people can gain various
amounts of knowledge, and know about world events as they occur. Purchasing on the
Internet is also becoming very popular, and has numerous advantage over the traditional,
shopping methods.
17. Training : It is much more cheaper and effective to teach pilots how to fly in a
computerized cockpit or simulators, than is real airplanes. This is because the learning pilots
will feel much more relaxed and confident due to the fact that no life is at risk at that
moment, Railway engineers can- also be given some kind of training on how to run a train
with the help of a computerized system. Training simulations are relatively cheaper and are
always available on one-to-one basis making way for persona training.
18. Paperwork: Computer systems will increasingly cut down the paperwork that is
involved- in millions of industries around the world. If a business is run on a manual system,
then the amount of papers or registers involved is a great deal, making the administration
process more tedious and error prone. If it is replaced by a computer system, then all the
necessary data and information is transferred into the memory-of the computer. This makes
managing various tasks easier, faster and more effective than the manual system.
Organizations that involve administrative tasks such as a hate!, school, hospitals, clubs,
libraries etc.. will become more efficient if a Computer system is implemented. ‘ -
19. Real Time systems : Many computers provide an environment, which is completely
based on real time. This means processing of one entity is done so quickly and effectively,
that another entity is not effected. For example Airline systems and Banking systems will
come under this category. These systems are immensely huge because they interact with all
other airlines or baking systems in the world. A computer system, therefore, becomes more
than just necessary in daily uses.
There are so many applications of computers, that it is impractical to mention all of them.
This is the Compl4ter Age and these machines are beginning to affect out lives in many
ways.- Computers are now becoming faster, more reliable, effective and whole lot cheaper
than they had been ever before Computers are all around us and avoiding them ‘is virtually
impossible. We have been exposed in the world of computer hype, computer advertisements
and computer headlines.
Q 11 What do you mean by data and information give difference between data and
information7 Give the various features of information?
Ans Data A collection of facts, concepts or instructions are celled data Information It is the
organized or processed data or it is organized data that has been arranged for better
comprehension or understanding
Features of Information the followings are the important features information
1 Relevance : Relevance is the degree to which products and services are useful and
responsive to users’ needs Relevance of data products and analytic reports may be monitored
through a professional review process and ongoing contacts with data users Product relevance
may be indicated by customer satisfaction with product content, information from customers
about product use, demonstration of product improvements, comparability with other data
series, agency responses to customer suggestions for improvement, new or customized
products/services, frequency of use, or responses to data requests from users (including
policy makers)
2 Accuracy : Accuracy measures the important features of correctness, validity, and
reliability of data and information products measured as degree of closeness to target values
For statistical data, accuracy may be defined as the degree of closeness to the target value and
niesured as sampling error and various aspects of non-sampling error (e g, response rates, size
of revisions, coverage, and edit performance)
3 Consistency : By consistency, we mean that the information is derived from the data
that has a consistent pattern of period The quality information is always consistent The
regularity in providing the information aids in maintaining the consistency
4 Timeliness : Timeliness is the timing of information releases Timeliness may be
measured as time from the close of the reference period to the release of information, or
customer satisfaction with timeliness may also be measured as how well agencies meet
scheduled and publicized release dates, expressed as a percent of release dates met
Qualitative or quantitative indicators may measure timeliness
5 Impartiality : By impartial information, we mean the information that does not contain
any biases That is it has been collected without distorting the view of the situation If some
prejudices are there preconceived and predetermined goals are there, then the factors may
lead to partiality The impartial information cannot be considered to possess quality
6 Validity : By validity, we mean the property that indicates the purpose of the
information due to which it was put to use It means to what extent the information is meeting
the purpose for which is it collected The quality information indicates that it valid
information
7 Cost : Cost is the amount used to produce data products or services The development
and use of financial performance measures within the Federal Government is an established
goal, and the intent of such measures is to determine the “true costs’ of various programs or
alternative modes of operation at the Federal level B Dissemination. Dissemination is the
availability, accessibility, and distribution of information products and services
Q 12 Discuss the important features of various generation of computer?
Ans.
FIRSTGENERATION (1951-1958)
Characteristics of First Generation Computers
1. Use of vacuum tubes in electronic circuits : These tubes controlled internal
operations and were huge. As a consequence the machines were large.
2. Magnetic drum : as primary internal-storage medium: Electric currents passed
through wires which magnetized the core to represent on and off states
3. Slow input/output, punched-card-oriented: Operators performed input and output
operations through the use of punched cards.
4. Low level symbolic-language programming : The computer used machine language
which was cumbersome and accomplished through long strings of numbers made up of
Zeroes and Ones. In 1952, Dr. Grace Hopper (University of Pennsylvania) developed a
symbolic language called mnemonics (Instructions written with symbolic codes). Rather than
writing instructions with Zeroes and Ones, the mnemonics were translated into binary code.
Dr. Hopper developed the first set of programs or instructions to tell computers how to
translate the mnemonics.
5. Heat and maintenance problems: Special air-conditioning and maintenance were
requires of the machines. The tubes gave off tremendous amounts of heat.
6. Applications: payrollprocessin and record keeping though still oriented toward
scientific applications that business data processing.
Examples: IBM 650 UNIVAC I
SECOND GENERATION COMPUTERS (1959-1964)
Characteristics of Second Generation Computers
1. Use of transistors for internal operations tiny solid state transistors replaces vacuum
tubes in computers. The heat problem was then minimized and computers could be made
smaller and faster.
2. Magnetic core as primary internal-storage medium: Electric currents pass through
wires which magnetize the core to represent on arid off states data in the-cores can be found
and retrieved for processing in a few millionths of a second.
3. Increased main-storage capacity : The internal or main storage was supplemented by
use of magnetic tapes for external storage. These tapes substituted for punched cards or
paper. Magnetic disks were also developed that stored information on circular tracks that
looked like phonograph records. The disks provided direct or random access to records in a
file.
4. Faster input/output; tape orientation: Devices could be connected directly to the
computer and considered “on-line”. This allowed for faster printing and detection and
correction of errors.
5. High-level programming languages (COBOL,FORTRAN) : These languages
resembled English. FORTRAN (Formula Translator) was the first high-level language that
was accepted widely. This language was used mostly for scientific applications. COBOL
(Common Business-Oriented Language) as developed in 1961 for business data processing
Its main features include file-processing, editing, and input/output capabilities
6 Increased speed and reliability Modular-hardware was developed through the design of
electronic circuits Complete modules called “breadboards” could be replaced if malfunctions
occurred, or the machine “crashed” This decreased lost time and also new modules could be
added for added features such as file-processing, editing , and input/output features
7 Batch-oriented applications Billing, payroll processing, updating and inventory files
Batch processing allowed for collection of data over a period time and then on processed in
one computer run The results were then stored on magnetic tapes
Examples: IBM 1401*(most popular business-oriented computer Honeywell 20( CDC 1604)
THIRD GENERATION COMPUTERS (1965-1970)
Characteristics of Third Generation Computers
1. Use of integrated circuits The use of integrated circuits (Ics) replaced thE transitors of the
second-generation machines The circuits are etched and printed and hundreds of electronic
components could be put on silicon circuit chips less than one eighth of an inch square
2 Magnetic core and solid-state main storage Greater storage capacity want to Developed
More flexibility with input/output, disk-oriented
4 Smaller size and better performance and reliability Advances in solid state technology
allowed for the design and building of smaller and faster computers Breadboards could easily
be replaced on the fly
5. Extensive use of high-level programming languages The software industry evolved during
this time Many users found that it was more cost effective to buy pre programmed packages
than to write the programs themselves The programs from the second generation had to be
rewritten since many of the programs were based on second generation architecture
6 Emergence of minicomputers The mini computers offered many of the same features as the
mainframe computers only on a smaller scale These machines filled till needs of the small
business owner
7 Remote processing and time-sharing through communication Computer were then able to
perform several operations at the same time Remote terminals were developed to
communicate with a central computer over a specific geographic location Time sharing
environments were established
3 Availability of operdting-systems(software) to control I/O and do tasks handle by human
operators Software was developed to take care of routine tasks required the computer freed
up the human operator
9 Applications such as airline reservation systems, market forcasting, credit card billing The
applications also included inventory, control, and scheduling labor and natenals. Multitasking
was also accomplished. Both scientific and business applications -
could be run oil the same machine.
Examples : IBM System/360 NCR 395 Burroughs B6500 FOURTH GENERATION (1970-)
Characteristics of Fourth Generation Computers:
1. Use of large scale integrated circuits
2. Increased storage capacity and speed.
3. Modular design and compatibility between equipment
4. Special application programs
5. Versatility of input/output devices
6. Increased use of minicomputers
7. Introduction of microprocessors and microcomputers.
Q 13 What are the different types of software?
Ans. Practical computer systems divide software into three major classes:
system software, programming software and application software, although the distinction
in arbitrary, and often blurred.
System software helps run the computer hardware and computer system. It includes operating
systems, device drivers, diagnostic tools, servers, windowing systems, utilities and more. The
purpose of systems software is to insulate the applications programmer as much as possible
from the details of the particular computer complex being used, especially memory and other
hardware features, and such accessory devices as communications, printers, readers, displays,
keyboards, etc. Programming software usually provides toots to assist a programmer in
writing computer programs and software using different programming languages in a
more convenient way. The tools include text editors, compilers, interpreters, linkers,
debuggers, and so on. An Integrated development environment (IDE) merges those tools into
software bundle, and a programmer may not nee6to type multiple commands for compiling,
interpreter, debugging, tracing, and etc., because the IDE usually has an advanced graphical
user interface, or GUI.. .
Application software allows end users..to accomplish one or more specific (non filled
computer related) tasks. Typical applications include industrial automation, business
software, educational software, medical software, databases, and computer games. 6usinesses
are probably the biggest users of application software, but almost every held of human
activity now uses some form of application software. It is used to automate all sorts of
functions.
Q 17. What are the various application software?
Ans. Application software
The mostly wide used are such application software packages:
• Text processing software
• Graphical software
• Electronic spreadsheets,
* Data base management systems
• Expert systems
• Computer aided design and engineering systems
• Mathematical, statistical, simulation packages
• Telecommunication software
• Integrated common use packages
• Packages expanding system software possibilities
• The text processing software wide spread when personal computers appeared This software
is divided into three groups
• Text editors are the simplest programs enabling to write edit and print the text using one
font type (Notepad, NC editor). The text can be saved into text file (.txt).
• Text processors include additional possibilities to use different font types and sizes, to
perform sophisticated formatting, to include illustrations and correct mistakes (Word).
• Desktop publishing systems are used to arrange large pages with text and illustrations, to
prepare the final design suitable for publishing (PageMaker). Graphical software is used to
create paintings and illustrations, to make charts and graphs (Paintbrush, CorelDraw). High-
level programming languages include integrated graphical libraries (GRAFOR in
FORTRAN, GRAPH in Pascal).
Graphical presentation software is treated as separate subgroup; it is appointed to prepare and
present various types of graphical and illustration materials (Power Point).
Electronic spreadsheet software i used to create tables, which can hold texts, numbers and
formulas they enable to create good organized reports, which may include results of various
calculations and graphs created on spreadsheet data. Spreadsheets are used in accountings
and other economic and technical calculations typical spreadsheet software is MS Excel and
Lotus 1-2-3.
Q 15. Describe the evolution of programming languages.
Ever since the invention of Charles Babbage’s difference engine in 1822, computers have
required a means of instructing them to perform a specific task. This means is known as a
programming language. Computer languages were first composed of a series of steps to wire
a particular program; these morphed into a series of steps keyed into the computer and then
executed; later these languages acquired advanced features such as logical branching and
object orientation. The computer languages of the last fifty years have come in two stages,
the first major languages and the second major languages, which are in use today.
In the beginning, Charles Babbage’s difference engine could only be made to execute tasks
by changing the gears which executed the calculations. Thus, the earliest form of a computer
language was physical motion. Eventually, physical motion was replaced by electrical signals
when the US Government built the ENIAC in 1942. It followed many of the same principles
of Babbage’s engine and hence, could only be “programmed” by presetting switches and
rewiring the entire system for each new “program” or calculation. This process proved to be
very tedious.
In 1945, John Von Neumann was working at the Institute for Advanced Study. He developed
two important concepts that directly affected the path of computer programming languages.
The first was known as “shared-program technique” (www.softlord.com). This technique
stated that the actual computer hardware should be simple and not need to be hand-wired for
each program. Instead, complex instructions should be used to control the simple hardware,
allowing it to be reprogrammed much faster.
The second concept was also extremely important to the development of programming
languages. Von Neumann called it “conditional control transfer” (www.softlord.com). This
idea gave rise to the notion of subroutines, or small blocks of code that could be jumped to in
any order, instead of a single set of chronologically ordered steps for the computer to take.
The second part of the idea stated that computer code should be able to branch based on
logical statements such as IF (expression) THEN, and looped such as with a FOR statement.
“Conditional control transfer” gave rise to the idea of “libraries,” which are blocks of code
that can be reused over and over.
In 1949, a few years after Von Neumann’s work, the language Short Code appeared
(www.byte.com). It was the first computer language for electronic devices and it required the
programmer to change its statements into 0’s and 1’s by hand. Still, it was the first step
towards the complex languages of today. In 1951, Grace Hopper wrote the first compiler, A-0
(www.byte.com). A compiler is a program that turns the language’s statements into 0’s and
1’s for the computer to understand. This lead to faster programming, as the programmer no
longer had to do the work by hand.
In 1957, the first of the major languages appeared in the form of FORTRAN. Its name stands
for FORmula TRANslating system. The language was designed at IBM for scientific
computing. The components were very simple, and provided the programmer with low-level
access to the computers innards. Today, this language would be considered restrictive as it
only included IF, DO, and GOTO statements, but at the time, these commands were a big
step forward. The basic types of data in use today got their start in FORTRAN, these included
logical variables (TRUE or FALSE), and integer, real, and double-precision numbers.
Though FORTAN was good at handling numbers, it was not so good at handling input and
output, which mattered most to business computing. Business computing started to take off in
1959, and because of this, COBOL was developed. It was designed from the ground up as the
language for businessmen. Its only data types were numbers and strings of text. It also
allowed for these to be grouped into arrays and records, so that data could be tracked and
organized better. It is interesting to note that a COBOL program is built in a way similar to an
essay, with four or five major sections that build into an elegant whole. COBOL statements
also have a very English-like grammar, making it quite easy to learn. All of these features
were designed to make it easier for the average business to learn and adopt it.
In 1958, John McCarthy of MIT created the LISt Processing (or LISP) language. It was
designed for Artificial Intelligence (AI) research. Because it was designed for a specialized
field, the original release of LISP had a unique syntax: essentially none. Programmers wrote
code in parse trees, which are usually a compiler-generated intermediary between higher
syntax (such as in C or Java) and lower-level code. Another obvious difference between this
language (in original form) and other languages is that the basic and only type of data is the
list; in the mid-1960’s, LISP acquired other data types. A LISP list is denoted by a sequence
of items enclosed by parentheses. LISP programs themselves are written as a set of lists, so
that LISP has the unique ability to modify itself, and hence grow on its own. The LISP syntax
was known as “Cambridge Polish,” as it was very different from standard Boolean logic
(Wexelblat, 177):
x V y - Cambridge Polish, what was used to describe the LISP program
OR(x,y) - parenthesized prefix notation, what was used in the LISP program
x OR y - standard Boolean logic
LISP remains in use today because its highly specialized and abstract nature.
The Algol language was created by a committee for scientific use in 1958. It’s major
contribution is being the root of the tree that has led to such languages as Pascal, C, C++, and
Java. It was also the first language with a formal grammar, known as Backus-Naar Form or
BNF (McGraw-Hill Encyclopedia of Science and Technology, 454). Though Algol
implemented some novel concepts, such as recursive calling of functions, the next version of
the language, Algol 68, became bloated and difficult to use (www.byte.com). This lead to the
adoption of smaller and more compact languages, such as Pascal.
Pascal was begun in 1968 by Niklaus Wirth. Its development was mainly out of necessity for
a good teaching tool. In the beginning, the language designers had no hopes for it to enjoy
widespread adoption. Instead, they concentrated on developing good tools for teaching such
as a debugger and editing system and support for common early microprocessor machines
which were in use in teaching institutions.
Pascal was designed in a very orderly approach, it combined many of the best features of the
languages in use at the time, COBOL, FORTRAN, and ALGOL. While doing so, many of the
irregularities and oddball statements of these languages were cleaned up, which helped it gain
users (Bergin, 100-101). The combination of features, input/output and solid mathematical
features, made it a highly successful language. Pascal also improved the “pointer” data type,
a very powerful feature of any language that implements it. It also added a CASE statement,
that allowed instructions to to branch like a tree in such a manner:
CASE expression OF
possible-expression-value-1:
statements to execute...
possible-expression-value-2:
statements to execute...
END
Pascal also helped the development of dynamic variables, which could be created while a
program was being run, through the NEW and DISPOSE commands. However, Pascal did
not implement dynamic arrays, or groups of variables, which proved to be needed and led to
its downfall (Bergin, 101-102). Wirth later created a successor to Pascal, Modula-2, but by
the time it appeared, C was gaining popularity and users at a rapid pace.
C was developed in 1972 by Dennis Ritchie while working at Bell Labs in New Jersey. The
transition in usage from the first major languages to the major languages of today occurred
with the transition between Pascal and C. Its direct ancestors are B and BCPL, but its
similarities to Pascal are quite obvious. All of the features of Pascal, including the new ones
such as the CASE statement are available in C. C uses pointers extensively and was built to
be fast and powerful at the expense of being hard to read. But because it fixed most of the
mistakes Pascal had, it won over former-Pascal users quite rapidly.
Ritchie developed C for the new Unix system being created at the same time. Because of this,
C and Unix go hand in hand. Unix gives C such advanced features as dynamic variables,
multitasking, interrupt handling, forking, and strong, low-level, input-output. Because of this,
C is very commonly used to program operating systems such as Unix, Windows, the MacOS,
and Linux.
In the late 1970’s and early 1980’s, a new programing method was being developed. It was
known as Object Oriented Programming, or OOP. Objects are pieces of data that can be
packaged and manipulated by the programmer. Bjarne Stroustroup liked this method and
developed extensions to C known as “C With Classes.” This set of extensions developed into
the full-featured language C++, which was released in 1983.
C++ was designed to organize the raw power of C using OOP, but maintain the speed of C
and be able to run on many different types of computers. C++ is most often used in
simulations, such as games. C++ provides an elegant way to track and manipulate hundreds
of instances of people in elevators, or armies filled with different types of soldiers. It is the
language of choice in today’s AP Computer Science courses.
In the early 1990’s, interactive TV was the technology of the future. Sun Microsystems
decided that interactive TV needed a special, portable (can run on many types of machines),
language. This language eventually became Java. In 1994, the Java project team changed
their focus to the web, which was becoming “the cool thing” after interactive TV failed. The
next year, Netscape licensed Java for use in their internet browser, Navigator. At this point,
Java became the language of the future and several companies announced applications which
would be written in Java, none of which came into use.
Though Java has very lofty goals and is a text-book example of a good language, it may be
the “language that wasn’t.” It has serious optimization problems, meaning that programs
written in it run very slowly. And Sun has hurt Java’s acceptance by engaging in political
battles over it with Microsoft. But Java may wind up as the instructional language of
tomorrow as it is truly object-oriented and implements advanced techniques such as true
portability of code and garbage collection.
Visual Basic is often taught as a first programming language today as it is based on the
BASIC language developed in 1964 by John Kemeny and Thomas Kurtz. BASIC is a very
limited language and was designed for non-computer science people. Statements are chiefly
run sequentially, but program control can change based on IF..THEN, and GOSUB
statements which execute a certain block of code and then return to the original point in the
program’s flow.
Microsoft has extended BASIC in its Visual Basic (VB) product. The heart of VB is the form,
or blank window on which you drag and drop components such as menus, pictures, and slider
bars. These items are known as “widgets.” Widgets have properties (such as its color) and
events (such as clicks and double-clicks) and are central to building any user interface today
in any language. VB is most often used today to create quick and simple interfaces to other
Microsoft products such as Excel and Access without needing a lot of code, though it is
possible to create full applications with it.
Perl has often been described as the “duct tape of the Internet,” because it is most often used
as the engine for a web interface or in scripts that modify configuration files. It has very
strong text matching functions which make it ideal for these tasks. Perl was developed by
Larry Wall in 1987 because the Unix sed and awk tools (used for text manipulation) were no
longer strong enough to support his needs. Depending on whom you ask, Perl stands for
Practical Extraction and Reporting Language or Pathologically Eclectic Rubbish Lister.
Programming languages have been under development for years and will remain so for many
years to come. They got their start with a list of steps to wire a computer to perform a task.
These steps eventually found their way into software and began to acquire newer and better
features. The first major languages were characterized by the simple fact that they were
intended for one purpose and one purpose only, while the languages of today are
differentiated by the way they are programmed in, as they can be used for almost any
purpose. And perhaps the languages of tomorrow will be more natural with the invention of
quantum and biological computers.
Unit 2
Q1. Explain C program structure.
A C program basically has the following form:
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
The following program is written in the C programming language. Open a text file hello.c using vi editor and put the following lines inside that file.
#include <stdio.h>
int main(){ /* My first program */ printf("Hello, World! \n"); return 0;}
Preprocessor Commands: These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. You will learn more about C Preprocessors in C Preprocessors session.
Functions: are main building blocks of any C Program. Every C Program will have one or more functions and there is one mandatory function which is called main() function. This function is prefixed with keyword int which means this function returns an integer value when it exits. This integer value is retured using return statement.
The C Programming language provides a set of built-in functions. In the above example printf()is a C built-in function which is used to print anything on the screen. Check Builtin functionsection for more detail.
You will learn how to write your own functions and use them in Using Function session.
Variables: are used to hold numbers, strings and complex data for manipulation. You will learn in detail about variables in C Variable Types.
Statements & Expressions : Expressions combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs.
Comments: are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/ as given in the example above. A comment can span through multiple lines.
Note the followings
C is a case sensitive programming language. It means in C printf and Printf will have different meanings.
C has a free-form line structure. End of each C statement must be marked with a semicolon.
Multiple statements can be one the same line.
White Spaces (ie tab space and space bar ) are ignored.
Statements can continue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files name. Assuming your compiler's name is cc and program file name is hello.c, give following command at Unix prompt.
$cc hello.c
This will produce a binary file called a.out and an object file hello.o in your current directory. Here a.out is your first program which you will run at Unix prompt like any other system program. If you don't like the name a.out then you can produce a binary file with your own name by using -o option while compiling C program. See an example below
$cc -o hello hello.c
Now you will get a binary with name hello. Execute this program at Unix prompt but before executing / running this program make sure that it has execute permission set. If you don't know what is execute permission then just follow these two steps
$chmod 755 hello$./hello
This will produce following resultHello, World
Q2. Explain the following:
Constants, Literals, variables, expressions
Ans: The constants refer to fixed values that the program may not alter during its execution.
These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a
character constant, or a string literal. There are also enumeration constants as well.
The constants are treated just like regular variables except that their values cannot be
modified after their definition.
A variable is nothing but a name given to a storage area that our programs can manipulate.
Each variable in C has a specific type, which determines the size and layout of the variable's
memory; the range of values that can be stored within that memory; and the set of operations
that can be applied to the variable.
The name of a variable can be composed of letters, digits, and the underscore character. It
must begin with either a letter or an underscore. Upper and lowercase letters are distinct
because C is case-sensitive.
An expression represents a single data item--usually a number. The expression may consist
of a single entity, such as a constant or variable, or it may consist of some combination of
such entities, interconnected by one or more operators. Expressions can also represent logical
conditions which are either true or false. However, in C, the conditions true and false are
represented by the integer values 1 and 0, respectively. Several simple expressions are given
below:
a + b
x = y
t = u + v
x <= y
++j
The first expression, which employs the addition operator (+), represents the sum of the
values assigned to variables a and b. The second expression involves the assignment
operator(=), and causes the value represented by y to be assigned to x. In the third
expression, the value of the expression (u + v) is assigned to t. The fourth expression takes
the value 1 (true) if the value of x is less than or equal to the value of y. Otherwise, the
expression takes the value 0 (false). Here, <= is a relational operator that compares the
values of x and y. The final example causes the value of j to be increased by 1.
A statement causes the computer to carry out some definite action. There are three different
classes of statements in C: expression statements, compound statements, and control
statements.
An expression statement consists of an expression followed by a semicolon. The execution of
such a statement causes the associated expression to be evaluated.
Q3. What are reserved keywords?
Ans: The following names are reserved by the C language. Their meaning is already defined, and they cannot be re-defined to mean anything else.
auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double
While naming your functions and variables, other than these names, you can choose any names of reasonable length for variables, functions etc.
Q4. Explain types of variables.
Ans: there will be the following basic variable types:
Type Description
char Typically a single octet(one byte). This is an integer type.
int The most natural size of integer for the machine.
float A single-precision floating point value.
double A double-precision floating point value.
void Represents the absence of type.
C programming language also allows to define various other types of variables, which we
will cover in subsequent chapters like Enumeration, Pointer, Array, Structure, Union, etc.
For this chapter, let us study only basic variable types.
Variable Definition in C:
A variable definition means to tell the compiler where and how much to create the storage
for the variable. A variable definition specifies a data type and contains a list of one or more
variables of that type as follows:
type variable_list;
Here, type must be a valid C data type including char, w_char, int, float, double, bool or any
user-defined object, etc., and variable_list may consist of one or more identifier names
separated by commas. Some valid declarations are shown here:
int i, j, k;
char c, ch;
float f, salary;
double d;
The line int i, j, k; both declares and defines the variables i, j and k; which instructs the
compiler to create variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration. The initializer
consists of an equal sign followed by a constant expression as follows:
type variable_name = value;
Some examples are:
extern int d = 3, f = 5; // declaration of d and f.
int d = 3, f = 5; // definition and initializing d and f.
byte z = 22; // definition and initializes z.
char x = 'x'; // the variable x has the value 'x'.
For definition without an initializer: variables with static storage duration are implicitly
initialized with NULL (all bytes have the value 0); the initial value of all other variables is
undefined.
Variable Declaration in C:
A variable declaration provides assurance to the compiler that there is one variable existing
with the given type and name so that compiler proceed for further compilation without
needing complete detail about the variable. A variable declaration has its meaning at the
time of compilation only, compiler needs actual variable declaration at the time of linking of
the program.
A variable declaration is useful when you are using multiple files and you define your
variable in one of the files which will be available at the time of linking of the program. You
will use extern keyword to declare a variable at any place. Though you can declare a
variable multiple times in your C program but it can be defined only once in a file, a
function or a block of code.
Example
Try following example, where variables have been declared at the top, but they have been
defined and initialized inside the main function:
#include <stdio.h>
// Variable declaration:
extern int a, b;
extern int c;
extern float f;
int main ()
{
/* variable definition: */
int a, b;
int c;
float f;
/* actual initialization */
a = 10;
b = 20;
c = a + b;
printf("value of c : %d \n", c);
f = 70.0/3.0;
printf("value of f : %f \n", f);
return 0;
}
When the above code is compiled and executed, it produces the following result:
value of c : 30
value of f : 23.333334
Q5. Explain Lvalues and Rvalues in C
There are two kinds of expressions in C:
1. lvalue : Expressions that refer to a memory location is called "lvalue" expression. An
lvalue may appear as either the left-hand or right-hand side of an assignment.
2. rvalue : The term rvalue refers to a data value that is stored at some address in
memory. An rvalue is an expression that cannot have a value assigned to it which
means an rvalue may appear on the right- but not left-hand side of an assignment.
Variables are lvalues and so may appear on the left-hand side of an assignment. Numeric
literals are rvalues and so may not be assigned and can not appear on the left-hand side.
Following is a valid statement:
int g = 20;
But following is not a valid statement and would generate compile-time error:
10 = 20;
Q6. Explain various operators available in C.
Ans. Operators in C
An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations. C is rich in built-in operators and provides following type of operators:
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
Arithmetic Operators:
There are following arithmetic operators supported by C language:
Assume variable A holds 10 and variable B holds 20 then:
Show Examples
Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiply both operands A * B will give 200
/ Divide numerator by de-numerator B / A will give 2
%Modulus Operator and remainder of
after an integer divisionB % A will give 0
++Increment operator, increases integer
value by oneA++ will give 11
--Decrement operator, decreases integer
value by oneA-- will give 9
Relational Operators:
There are following relational operators supported by C language
Assume variable A holds 10 and variable B holds 20 then:
Show Examples
Operator Description Example
==
Checks if the value of two operands is
equal or not, if yes then condition
becomes true.
(A == B) is not true.
!=
Checks if the value of two operands is
equal or not, if values are not equal then
condition becomes true.
(A != B) is true.
>
Checks if the value of left operand is
greater than the value of right operand, if
yes then condition becomes true.
(A > B) is not true.
<
Checks if the value of left operand is less
than the value of right operand, if yes
then condition becomes true.
(A < B) is true.
>=
Checks if the value of left operand is
greater than or equal to the value of right
operand, if yes then condition becomes
true.
(A >= B) is not true.
<=
Checks if the value of left operand is less
than or equal to the value of right
operand, if yes then condition becomes
true.
(A <= B) is true.
Logical Operators:
There are following logical operators supported by C language
Assume variable A holds 1 and variable B holds 0 then:
Show Examples
Operator Description Example
&&
Called Logical AND operator. If both the
operands are non zero then condition
becomes true.
(A && B) is false.
||
Called Logical OR Operator. If any of
the two operands is non zero then
condition becomes true.
(A || B) is true.
!
Called Logical NOT Operator. Use to
reverses the logical state of its operand.
If a condition is true then Logical NOT
operator will make false.
!(A && B) is true.
Bitwise Operators:
Bitwise operator works on bits and perform bit by bit operation. The truth tables for &, |, and
^ are as follows:
P q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Assume if A = 60; and B = 13; Now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
The Bitwise operators supported by C language are listed in the following table. Assume
variable A holds 60 and variable B holds 13 then:
Operator Description Example
&Binary AND Operator copies a bit to the
result if it exists in both operands.(A & B) will give 12 which is 0000 1100
|Binary OR Operator copies a bit if it
exists in either operand.(A | B) will give 61 which is 0011 1101
^Binary XOR Operator copies the bit if it
is set in one operand but not both.(A ^ B) will give 49 which is 0011 0001
~Binary Ones Complement Operator is
unary and has the effect of 'flipping' bits.(~A ) will give -60 which is 1100 0011
<<
Binary Left Shift Operator. The left
operands value is moved left by the
number of bits specified by the right
operand.
A << 2 will give 240 which is 1111 0000
>>
Binary Right Shift Operator. The left
operands value is moved right by the
number of bits specified by the right
operand.
A >> 2 will give 15 which is 0000 1111
Assignment Operators:
There are following assignment operators supported by C language:
Show Examples
Operator Description Example
=
Simple assignment operator,
Assigns values from right side
operands to left side operand
C = A + B will assign value of A +
B into C
+= Add AND assignment operator, It
adds right operand to the left
operand and assign the result to left
C += A is equivalent to C = C + A
operand
-=
Subtract AND assignment
operator, It subtracts right operand
from the left operand and assign
the result to left operand
C -= A is equivalent to C = C – A
*=
Multiply AND assignment
operator, It multiplies right
operand with the left operand and
assign the result to left operand
C *= A is equivalent to C = C * A
/=
Divide AND assignment operator,
It divides left operand with the
right operand and assign the result
to left operand
C /= A is equivalent to C = C / A
%=
Modulus AND assignment
operator, It takes modulus using
two operands and assign the result
to left operand
C %= A is equivalent to C = C %
A
<<=Left shift AND assignment
operatorC <<= 2 is same as C = C << 2
>>=Right shift AND assignment
operatorC >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator C &= 2 is same as C = C & 2
^=bitwise exclusive OR and
assignment operatorC ^= 2 is same as C = C ^ 2
|= bitwise inclusive OR and C |= 2 is same as C = C | 2
assignment operator
Q7. Describe control flow statements and its types.
Ans:
C provides two sytles of flow control:
Branching Looping
Branching is deciding what actions to take and looping is deciding how many times to take a certain action.
Branching:
Branching is so called because the program chooses to follow one branch or another.
if statement
This is the most simple form of the branching statements.
It takes an expression in parenthesis and an statement or block of statements. if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.
NOTE: Expression will be assumed to be true if its evaulated values is non-zero.
if statements take the following form:
if (expression) statement;
or
if (expression) { Block of statements; }
or
if (expression) { Block of statements; }else
{ Block of statements; }
or
if (expression) { Block of statements; }else if(expression) { Block of statements; }else { Block of statements; }
? : Operator
The ? : operator is just like an if ... else statement except that because it is an operator you can use it within expressions.
? : is a ternary operator in that it takes three values, this is the only ternary operator C has.
? : takes the following form:
Show Example
if condition is true ? then X return value : otherwise Y value;
switch statement:
The switch statement is much like a nested if .. else statement. Its mostly a matter of preference which you use, switch statement can be slightly more efficient and easier to read.
Show Example
switch( expression ) { case constant-expression1: statements1; [case constant-expression2: statements2;] [case constant-expression3: statements3;] [default : statements4;] }
Using break keyword:
If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement. This is achieved by using break keyword.
What is default condition:
If none of the listed conditions is met then default condition executed.
Looping
Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way.
while loop
The most basic loop in C is the while loop.A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statments get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again.This cycle repeats until the test condition evaluates to false.
Basic syntax of while loop is as follows:
Show Example
while ( expression ){ Single statement or Block of statements;}
for loop
for loop is similar to while, it's just written differently. for statements are often used to proccess lists such a range of numbers:
Basic syntax of for loop is as follows:
Show Example
for( expression1; expression2; expression3){ Single statement or
Block of statements;}
In the above syntax:
expression1 - Initialisese variables. expression2 - Condtional expression, as long as this condition is true, loop will keep
executing. expression3 - expression3 is the modifier which may be simple increment of a
variable.
do...while loop
do ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once.
Basic syntax of do...while loop is as follows:
Show Example
do{ Single statement or Block of statements;}while(expression);
break and continue statements
C provides two commands to control how we loop:
break -- exit form loop or switch. continue -- skip 1 iteration of loop.
You already have seen example of using break statement. Here is an example showing usage ofcontinue statement.
#include
main(){ int i; int j = 10;
for( i = 0; i <= j; i ++ ) {
if( i == 5 ) { continue; } printf("Hello %d\n", i ); }}
This will produce following output:
Hello 0Hello 1Hello 2Hello 3Hello 4Hello 6Hello 7Hello 8Hello 9Hello 10
Q8. What are random numbers?
Ans: The C library function int rand(void) returns a pseudo-random number in the range of
0 to RAND_MAX.
RAND_MAX is a constant whose default value may vary between implementations but it is
granted to be at least 32767.
Declaration
Following is the declaration for rand() function.
int rand(void)
Return Value
This function returns an integer value between 0 and RAND_MAX.
Q9. What are functions?
Ans:
A function is a module or block of program code which deals with a particular task. Making functions is a way of isolating one block of code from other independent blocks of code.
Functions serve two purposes.
They allow a programmer to say: `this piece of code does a specific job which stands by itself and should not be mixed up with anyting else',
Second they make a block of code reusable since a function can be reused in many different contexts without repeating parts of the program text.
A function can take a number of parameters, do required processing and then return a value. There may be a function which does not return any value.
You already have seen couple of built-in functions like printf(); Similar way you can define your own functions in C language.
Consider the following chunk of code
int total = 10; printf("Hello World"); total = total + l;
To turn it into a function you simply wrap the code in a pair of curly brackets to convert it into a single compound statement and write the name that you want to give it in front of the brackets:
Demo(){ int total = 10; printf("Hello World"); total = total + l;}
curved brackets after the function's name are required. You can pass one or more paramenters to a function as follows:
Demo( int par1, int par2){ int total = 10; printf("Hello World"); total = total + l;}
By default function does not return anything. But you can make a function to return any value as follows:
int Demo( int par1, int par2){ int total = 10; printf("Hello World"); total = total + l;
return total;}
Q10. What is use of return()?
Ans: A return keyword is used to return a value and datatype of the returned value is specified before the name of function. In this case function returns total which is int type. If a function does not return a value then void keyword can be used as return value.
Once you have defined your function you can use it within a program:
main(){ Demo();}
Q11. How to declare and define a function?
Ans: Each function behaves the same way as C language standard function main(). So a function will have its own local variables defined. In the above example total variable is local to the function Demo.
A global variable can be accessed in any function in similar way it is accessed in main() function.
Declaration and Definition
When a function is defined at any place in the program then it is called function definition. At the time of definition of a function actual logic is implemented with-in the function.
A function declaration does not have any body and they just have their interfaces.
A function declaration is usually declared at the top of a C source file, or in a separate header file.
A function declaration is sometime called function prototype or function signature. For the aboveDemo() function which returns an integer, and takes two parameters a function declaration will be as follows:
int Demo( int par1, int par2);
Passing Parameters to a Function
There are two ways to pass parameters to a function:
Pass by Value: mechanism is used when you don't want to change the value of passed paramters. When parameters are passed by value then functions in C create copies of the passed in variables and do required processing on these copied variables.
Pass by Reference mechanism is used when you want a function to do the changes in passed parameters and reflect those changes back to the calling function. In this case only addresses of the variables are passed to a function so that function can work directly over the addresses.
Q12. What are pointers?
Ans: Pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk '*' in front of the variables identifier.
There are two new operators you will need to know to work with pointers. The "address of" operator '&' and the "dereferencing" operator '*'. Both are prefix unary operators.
When you place an ampersand in front of a variable you will get it's address, this can be stored in a pointer vairable.
When you place an asterisk in front of a pointer you will get the value at the memory address pointed to.
Q13. Describe the concept of arrays.
Ans: An array is a sequence of data item of homogeneous value(same type).
Arrays are of two types:
One-dimensional arrays
Multidimensional arrays ( will be discussed in next chapter )
Declaration of one-dimensional array
data_type array_name[array_size];
For example:
int age[5];
Here, the name of array is age. The size of array is 5,i.e., there are 5 items(elements) of array age. All element in an array are of the same type (int, in this case).
Array elements
Size of array defines the number of elements in an array. Each element of array can be accessed and used by user according to the need of program. For example:
int age[5];
Note that, the first element is numbered 0 and so on.
Here, the size of array age is 5 times the size of int because there are 5 elements.
Suppose, the starting address of age[0] is 2120d and the size of int be 4 bytes. Then, the next address (address of a[1]) will be 2124d, address of a[2] will be 2128d and so on.
Initialization of one-dimensional array:
Arrays can be initialized at declaration time in this source code as:
int age[5]={2,4,34,3,4};
It is not necessary to define the size of arrays during initialization.
int age[]={2,4,34,3,4};
In this case, the compiler determines the size of array by calculating the number of elements of an array.
Accessing array elements
In C programming, arrays can be accessed and treated like variables in C.
For example:
scanf("%d",&age[2]);
/* statement to insert value in the third element of array age[]. */
scanf("%d",&age[i]);
/* Statement to insert value in (i+1)th element of array age[]. */
/* Because, the first element of array is age[0], second is age[1], ith is age[i-1] and (i+1)th is age[i]. */
printf("%d",age[0]);
/* statement to print first element of an array. */
printf("%d",age[i]);
/* statement to print (i+1)th element of an array. */
Example of array in C programming
/* C program to find the sum marks of n students using arrays */
#include <stdio.h>
int main(){
int marks[10],i,n,sum=0;
printf("Enter number of students: ");
scanf("%d",&n);
for(i=0;i<n;++i){
printf("Enter marks of student%d: ",i+1);
scanf("%d",&marks[i]);
sum+=marks[i];
}
printf("Sum= %d",sum);
return 0;
}
Output
Enter number of students: 3
Enter marks of student1: 12
Enter marks of student2: 31
Enter marks of student3: 2
sum=45
Note:
Suppose, you declared the array of 10 students. For example: arr[10]. You can use array members from arr[0] to arr[9]. But, what if you want to use element arr[10], arr[13] etc. Compiler may not show error using these elements but, may cause fatal error during program execution
Q14. Why files are needed?
Ans: When the program is terminated, the entire data is lost in C programming. If you want to keep large volume of data, it is time consuming to enter the entire data. But, if file is created, these information can be accessed using few commands.
There are large numbers of functions to handle file I/O in C language. In this tutorial, you will learn to handle standard I/O(High level file I/O functions) in C.
High level file I/O functions can be categorized as:
Text file
Binary file
Q15. Explain working of different operations in a file?
Ans: File Operations
Creating a new file
Opening an existing file
Reading from and writing information to a file
Closing a file
While working with file, you need to declare a pointer of type file. This declaration is needed for communication between file and program.
FILE *ptr;
Opening a file
Opening a file is performed using library function fopen(). The syntax for opening a file in standard I/O is:
ptr=fopen("fileopen","mode")
For Example:
fopen("E:\\cprogram\program.txt","w");
E:\\cprogram\program.txt is the location to create file.
"w" represents the mode for writing.
Here, the program.txt file is opened for writing mode.
Opening Modes in Standard I/O
File Mode Meaning of Mode During Inexistence of file
r Open for reading.If the file does not exist, fopen() returns NULL.
w Open for writing.
If the file exists, its contents are overwritten. If the file does not exist, it will be created.
aOpen for append. i.e, Data is added to end of file. If the file does not exists, it will be created.
r+Open for both reading and writing.
If the file does not exist, fopen() returns NULL.
w+Open for both reading and writing.
If the file exists, its contents are overwritten. If the file does not exist, it will be created.
a+Open for both reading and appending. If the file does not exists, it will be created.
Closing a File
The file should be closed after reading/writing of a file. Closing a file is performed using library function fclose().
fclose(ptr); //ptr is the file pointer associated with file to be closed.
The Functions fprintf() and fscanf() functions.
The functions fprintf() and fscanf() are the file version of printf() and fscanf(). The only difference while using fprintf() and fscanf() is that, the first argument is a pointer to the structure FILE
Writing to a file
#include <stdio.h>
int main()
{
int n;
FILE *fptr;
fptr=fopen("C:\\program.txt","w");
if(fptr==NULL){
printf("Error!");
exit(1);
}
printf("Enter n: ");
scanf("%d",&n);
fprintf(fptr,"%d",n);
fclose(fptr);
return 0;
}
This program takes the number from user and stores in file. After you compile and run this program, you can see a text file program.txt created in C drive of your computer. When you open that file, you can see the integer you entered.
Similarly, fscanf() can be used to read data from file.
Reading from file
#include <stdio.h>
int main()
{
int n;
FILE *fptr;
if ((fptr=fopen("C:\\program.txt","r"))==NULL){
printf("Error! opening file");
exit(1); /* Program exits if file pointer returns NULL. */
}
fscanf(fptr,"%d",&n);
printf("Value of n=%d",n);
fclose(fptr);
return 0;
}
If you have run program above to write in file successfully, you can get the integer back entered in that program using this program.
Other functions like fgetchar(), fputc() etc. can be used in similar way.
Q16. What are structures in C?
Ans: Structure is the collection of variables of different types under a single name for better handling. For example: You want to store the information about person about his/her name, citizenship number and salary. You can create these information separately but, better approach will be collection of these information under single name because all these information are related to person.
Structure Definition in C
Keyword struct is used for creating a structure.
Syntax of structure
struct structure_name
{
data_type member1;
data_type member2;
.
.
data_type memeber;
};
We can create the structure for a person as mentioned above as:
struct person
{
char name[50];
int cit_no;
float salary;
};
Q. 18 How structure is represented?
Ans. C arrays allow you to define type of variables that can hold several data items of the same kind but structure is another user defined data type available in C programming, which allows you to combine data items of different kinds.
Structures are used to represent a record, Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book:
• Title
• Author
• Subject
• Book ID
Defining a Structure
To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program. The format of the struct statement is this:
struct [structure tag]
{
member definition;
member definition;
...
member definition;
} [one or more structure variables];
The structure tag is optional and each member definition is a normal variable definition, such as int i; or float f; or any other valid variable definition. At the end of the structure's definition, before the final semicolon, you can specify one or more structure variables but it is optional.
Q19. Explain different types of Printers
Printer is an output device, which is used to print information on paper.
There are two types of printers:
Impact Printers
Non-Impact Printers
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
Character printers
Line printers
Character Printers
Character printers are the printers which print one character at a time.
These are further divided into two types:
Dot Matrix Printer(DMP)
Daisy Wheel
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.
These printers are of two types
Laser Printers
Inkjet Printers
Characteristics of Non-impact Printers
Faster than impact printers.
They are not noisy.
High quality.
Support many fonts and different character size.
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.
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
Ques 20 What are the various control structures available in C? Explain with example.
Ans Control structures form the basic entities of a “structured programming language“.
We all know languages like C/C++ or Java are all structured programming
languages. Control structures are used to alter the flow of execution of the
program. Why do we need to alter the program flow ? The reason is “decision making“! In
life, we may be given with a set of option like doing “Electronics” or “Computer science”.
We do make a decision by analyzing certain conditions (like our personal interest, scope of
job opportunities etc). With the decision we make, we alter the flow of our life’s direction.
This is exactly what happens in a C/C++ program. We use control structures to make
decisions and alter the direction of program flow in one or the other path(s) available.
There are three types of control structures available in C and C++
1) Sequence structure (straight line paths)
2) Selection structure (one or many branches)
3)Loop structure (repetition of a set of activities)
The control statements are:-
Switch
If
If Else
While
Do While
For
Selection structures are implemented using If , If Else and Switch statements.
Looping structures are implemented using While, Do While and For statements.
Selection structures
Selection structure
Selection structures are used to perform ‘decision making‘ and then branch the program
flow based on the outcome of decision making. Selection structures are implemented in C/C+
+ with If, If Else and Switch statements. If and If Else statements are 2 way branching
statements where as Switch is a multi branching statement.
The simple If statement
The syntax format of a simple if statement is as shown below.
if (expression) // This expression is evaluated. If expression is TRUE
statements inside the braces will be executed
{
statement 1;
statement 2;
}
statement 1;// Program control is transfered directly to this line, if the
expression is FALSE
statement 2;
The expression given inside the brackets after if is evaluated first. If the expression is true,
then statements inside the curly braces that follow if(expression) will be executed. If the
expression is false, the statements inside curly braces will not be executed and program
control goes directly to statements after curly braces.
Example program to demo “If” statement
Problem:-
A simple example program to demo the use of If, If Else and Switch is shown here. An
integer value is collected from user.
If the integer entered by user is 1 – output on screen “UNITED STATES”. If the integer is 2
– output “SPAIN”, If the integer is 3 output “INDIA”. If the user enters some other value –
output “WRONG ENTRY”.
Note:- The same problem is used to develop example programs for “if else” and “switch”
statements#include
void main()
{
int num;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
if(num==1)
{
printf("UNITED STATES");
}
if(num==2)
{
printf("SPAIN");
}
if(num==3)
{
printf("INDIA");
}
}
The If Else statement.
Syntax format for If Else statement is shown below.
if(expression 1)// Expression 1 is evaluated. If TRUE, statements inside
the curly braces are executed.
{ //If FALSE program control is transferred to immedate else if statement.
statement 1;
statement 2;
}
else if(expression 2)// If expression 1 is FALSE, expression 2 is
evaluated.
{
statement 1;
statement 2;
}
else if(expression 3) // If expression 2 is FALSE, expression 3 is
evaluated
{
statement 1;
statement 2;
}
else // If all expressions (1, 2 and 3) are FALSE, the statements that
follow this else (inside curly braces) is executed.
{
statement 1;
statement 2;
}
other statements;
The execution begins by evaluation expression 1. If it is TRUE, then statements inside the
immediate curly braces is evaluated. If it is FALSE, program control is transferred directly to
immediate else if statement. Here expression 2 is evaluated for TRUE or FALSE. The
process continues. If all expressions inside the different if and else if statements are FALSE,
then the last else statement (without any expression) is executed along with the statements 1
and 2 inside the curly braces of last else statement.
Switch statement
Switch is a multi branching control statement. Syntax for switch statement is shown below.
switch(expression)// Expression is evaluated. The outcome of the expression
should be an integer or a character constant
{
case value1: // case is the keyword used to match the integer/character
constant from expression.
//value1, value2 ... are different possible values that can come in
expression
statement 1;
statement 2;
break; // break is a keyword used to break the program control from switch
block.
case value2:
statement 1;
statement 2;
break;
default: // default is a keyword used to execute a set of statements inside
switch, if no case values match the expression value
statement 1;
statement 2;
break;
}
Execution of switch statement begins by evaluating the expression inside the switch keyword
brackets. The expression should be an integer (1, 2, 100, 57 etc ) or a character constant
like ‘a’, ‘b’etc. This expression’s value is then matched with each case values. There can be
any number of case values inside a switch statements block. If first case value is not matched
with the expression value, program control moves to next case value and so on. When a case
value matches with expression value, the statements that belong to a particular case
value are executed.
. The word default is a keyword in C/C++. When used inside switch block, it is intended to
execute a set of statements, if no case values matches with expression value. So if no case
values are matched with expression value, the set of statements that follow default: will get
executed.
Loop structures
Loop Structure
A loop structure is used to execute a certain set of actions for a predefined number of times or
until a particular condition is satisfied. There are 3 control statements available in C/C++ to
implement loop structures. While, Do while and For statements.
The while statement
Syntax for while loop is shown below:
while(condition)// This condition is tested for TRUE or FALSE. Statements
inside curly braces are executed as long as condition is TRUE
{
statement 1;
statement 2;
statement 3;
}
The condition is checked for TRUE first. If it is TRUE then all statements inside curly braces
are executed.Then program control comes back to check the condition has changed or to
check if it is still TRUE. The statements inside braces are executed repeatedly, as long as the
condition is TRUE. When the condition turns FALSE, program control exits from while loop.
Note:- while is an entry controlled loop. Statement inside braces are allowed to execute only
if condition inside while is TRUE.
Example program to demo working of “while loop”
An example program to collect a number from user and then print all numbers from zero to
that particular collected number is shown below. That is, if user enters 10 as input, then
numbers from 0 to 10 will be printed on screen.
Note:- The same problem is used to develop programs for do while and for loops#include
void main()
{
int num;
int count=0; // count is initialized as zero to start printing from zero.
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
while(count<=num) // Checks the condition - if value of count has reached
value of num or not.
{
printf("%d",count);
count=count+1; // value of count is incremented by 1 to print next number.
}
}
The do while statement
Syntax for do while loop is shown below:
do
{
statement 1;
statement 2;
statement 3;
}
while(condition);
Unlike while, do while is an exit controlled loop. Here the set of statements inside braces are
executed first. The condition inside while is checked only after finishing the first time
execution of statements inside braces. If the condition is TRUE, then statements are executed
again. This process continues as long as condition is TRUE. Program control exits the loop
once the condition turns FALSE.
Example program to demo working of "do while"
#include
void main()
{
int num;
int count=0; // count is initialized as zero to start printing from zero.
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
do
{
printf("%d",count); // Here value of count is printed for one time intially
and then only condition is checked.
count=count+1; // value of count is incremented by 1 to print next number.
}while(count<=num);
}
The for statement
Syntax of for statement is shown below:
for(initialization statements;test condition;iteration statements)
{
statement 1;
statement 2;
statement 3;
}
The for statement is an entry controlled loop. The difference between while and for is in the
number of repetitions. The for loop is used when an action is to be executed for a predefined
number of times. The while loop is used when the number of repetitions is not predefined.
Working of for loop:
The program control enters the for loop. At first it execute the statements given as
initialization statements. Then the condition statement is evaluated. If conditions are TRUE,
then the block of statements inside curly braces is executed. After executing curly brace
statements fully, the control moves to the "iteration" statements. After executing iteration
statements, control comes back to condition statements. Condition statements are evaluated
again for TRUE or FALSE. If TRUE the curly brace statements are executed. This
process continues until the condition turns FALSE.
Note 1:- The statements given as "initialization statements" are executed only once, at the
beginning of a for loop.
Note 2: There are 3 statements given to a for loop as shown. One for initialization purpose,
other for condition testing and last one for iterating the loop. Each of these 3 statements are
separated by semicolons.
Example program to demo working of "for loop"#include
void
main()
{
int num,count;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
for(count=0;count<=num;count++)// count is initialized to zero inside for
statement. The condition is checked and statements are
executed.
{
printf("%d",count); // Values from 0 are printed.
}
}
Ques 21 What are the steps in the design of a program? What is the
structure of a C program?
ans Steps to Design
There are three fundamental steps you should perform when you have a program to write:
1. Define the output and data flows.
2. Develop the logic to get to that output.
3. Write the program.
A C program basically consists of the following parts:
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
reprocessor Commands: These commands tells the compiler to do preprocessing
before doing actual compilation. Like #include <stdio.h> is a preprocessor command
which tells a C compiler to include stdio.h file before going to actual compilation.
You will learn more about C Preprocessors in C Preprocessors session.
Functions: are main building blocks of any C Program. Every C Program will have
one or more functions and there is one mandatory function which is
called main() function. This function is prefixed with keyword int which means this
function returns an integer value when it exits. This integer value is retured
using return statement.
The C Programming language provides a set of built-in functions. In the above
example printf() is a C built-in function which is used to print anything on the screen.
Check Builtin function section for more detail.
You will learn how to write your own functions and use them in Using
Function session.
Variables: are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions : Expressions combine variables and constants to create
new values. Statements are expressions, assignments, function calls, or control flow
statements which make up C programs.
Comments: are used to give additional useful information inside a C Program. All the
comments will be put inside /*...*/ as given in the example above. A comment can
span through multiple lines.
#include <stdio.h>
int main()
{
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
Let us look various parts of the above program:
1. The first line of the program #include <stdio.h> is a preprocessor command, which
tells a C compiler to include stdio.h file before going to actual compilation.
2. The next line int main() is the main function where program execution begins.
3. The next line /*...*/ will be ignored by the compiler and it has been put to add
additional comments in the program. So such lines are called comments in the
program.
4. The next line printf(...) is another function available in C which causes the message
"Hello, World!" to be displayed on the screen.
5. The next line return 0; terminates main()function and returns the value 0.
Compile & Execute C Program:
Lets look at how to save the source code in a file, and how to compile and run it. Following
are the simple steps:
1. Open a text editor and add the above-mentioned code.
2. Save the file as hello.c
3. Open a command prompt and go to the directory where you saved the file.
4. Type gcc hello.c and press enter to compile your code.
5. If there are no errors in your code the command prompt will take you to the next line
and would generate a.out executable file.
6. Now, type a.out to execute your program.
7. You will be able to see "Hello World" printed on the screen
$ gcc hello.c
$ ./a.out
Hello, World!
b) What is the syntax of various input and output statements available in C?
C support many input and output statements. It also supports formatted input and output.
Basic Character Input & Output:
getchar() function: It reads one character from the standard input. If there is no more
characters available, the special value EOF will be return.
Example: char c;
….
c=getchar();
putchar() function: It writes one character to the standard output (Monitor).
Example: char c;
c=”A”;
putchar(c);
Formatted Input:
Input data can be entered into the computer from a standard input device by means of the
standard C library function scanf(). This function can be used to enter any combination of
numerical values, single character and strings. The function returns the number of data items
that have been entered successfully.
Syntax: scanf( control string, arg1, arg2,….argn)
The control string consist of control characters, whitespace characters and nor-whitespace
characters. The control characters are preceded by a % sign and are listed below.
Control Character Explanation
%c A single character
%d A decimal integer
%i An integer
%e, %f, %g A floating-point number
%o An octal number
%s A string
%x A hexadecimal number
%p A pointer
%n An integer equal to the number of characters read so far
%u An unsigned integer
%[] A set of characters
%% A percent sign
Example: int i;
float f;
char c;
char str[10];
scanf(“%d %f %c %s”,&I,&f,&c,str);
Formatted Output:
Output data can be written from the computer onto a standard output device using the library
function printf(). This function can be used to output any combination of numerical values,
single characters and strings. It similar to the input function scanf(), except that its purpose is
to display data rather than enter into the computer.
Syntax: printf(control string, arg1, arg2, ….argn)
Ques 22 What is the life time and scope of various types of variable?
Ans Life Time – Life time of any variable is the time for which the particular variable
outlives in memory during running of the program.
Scope – The scope of any variable is actually a subset of life time. A variable may be in the
memory but may not be accessible though. So, the area of our program where we can actually
access our entity (variable in this case) is the scope of that variable.
The scope of any variable can be broadly categorized into three categories :
Global scope : When variable is defined outside all functions. It is then available to all
the functions of the program and all the blocks program contains.
Local scope : When variable is defined inside a function or a block, then it is locally
accessible within the block and hence it is a local variable.
Function scope : When variable is passed as formal arguments, it is said to have
function scope.
1
2
3
4
5
6
7
8
9
10
11
12
#include<stdio.h>
int global = 100; // global variable declared
void main()
{
int local = 10; // local variable declared
printf("Global variable is %d",global);
printf("Local variable is %d",local);
func1();
}
void func1()
{
13
14
15
printf("Global inside func1 is %d",global); // Would print the global variable
successfully.
}
Here we have a variable named global which is defined outside all the functions (generally at
the top of the program) , it is defined even outside main, and hence would be available to
every function defined in the program , here we consider only one function func1() .
The output of the above program would be :
Global variable is 100
Local variable is 10
Global inside func1 is 100
Q23. Explain switch statements?
Ans: A switch statement allows a variable to be tested for equality against a list of values.
Each value is called a case, and the variable being switched on is checked for each switch
case.
Syntax:
The syntax for a switch statement in C programming language is as follows:
switch(expression){
case constant-expression :
statement(s);
break; /* optional */
case constant-expression :
statement(s);
break; /* optional */
/* you can have any number of case statements */
default : /* Optional */
statement(s);
}
The following rules apply to a switch statement:
The expression used in a switch statement must have an integral or enumerated type,
or be of a class type in which the class has a single conversion function to an integral
or enumerated type.
You can have any number of case statements within a switch. Each case is followed
by the value to be compared to and a colon.
The constant-expression for a case must be the same data type as the variable in the
switch, and it must be a constant or a literal.
When the variable being switched on is equal to a case, the statements following that
case will execute until a break statement is reached.
When a break statement is reached, the switch terminates, and the flow of control
jumps to the next line following the switch statement.
Not every case needs to contain a break. If no break appears, the flow of control
will fall through to subsequent cases until a break is reached.
A switch statement can have an optional default case, which must appear at the end
of the switch. The default case can be used for performing a task when none of the
cases is true. No break is needed in the default case.
Q24. Explain concept of dynamic memory allocation.
Ans: The exact size of array is unknown untill the compile time,i.e., time when a compiler compiles code written in a programming language into a executable form. The size of array you have declared initially can be sometimes insufficient and sometimes more than required. Dynamic memory allocation allows a program to obtain more memory space, while running or to release space when no space is required.
Although, C language inherently does not has any technique to allocated memory dynamically, there are 4 library functions under "stdlib.h" for dynamic memory allocation.
Function Use of Function
malloc()Allocates requested size of bytes and returns a pointer first byte of allocated space
Function Use of Function
calloc()Allocates space for an array elements, initializes to zero and then returns a pointer to memory
free() dellocate the previously allocated space
realloc() Change the size of previously allocated space
malloc()
The name malloc stands for "memory allocation". The function malloc() reserves a block of memory of specified size and return a pointer of type void which can be casted into pointer of any form.
Syntax of malloc()
ptr=(cast-type*)malloc(byte-size)
Here, ptr is pointer of cast-type. The malloc() function returns a pointer to an area of memory with size of byte size. If the space is insufficient, allocation fails and returns NULL pointer.
ptr=(int*)malloc(100*sizeof(int));
This statement will allocate either 200 or 400 according to size of int 2 or 4 bytes respectively and the pointer points to the address of first byte of memory.
calloc()
The name calloc stands for "contiguous allocation". The only difference between malloc() and calloc() is that, malloc() allocates single block of memory whereas calloc() allocates multiple blocks of memory each of same size and sets all bytes to zero.
Syntax of calloc()
ptr=(cast-type*)calloc(n,element-size);
This statement will allocate contiguous space in memory for an array of n elements. For example:
ptr=(float*)calloc(25,sizeof(float));
This statement allocates contiguous space in memory for an array of 25 elements each of size of float, i.e, 4 bytes.
free()
Dynamically allocated memory with either calloc() or malloc() does not get return on its own. The programmer must use free() explicitly to release space.
syntax of free()
free(ptr);
This statement cause the space in memory pointer by ptr to be deallocated.
UNIT 3 Q1. Explain open standards.Ans: An open standard is a standard that is publicly available and has various rights to use associated with it, and may also have various properties of how it was designed (e.g. open process). There is no single definition and interpretations vary with usage.
The terms open and standard have a wide range of meanings associated with their usage. There are a number of definitions of open standards which emphasize different aspects of openness, including the openness of the resulting specification, the openness of the drafting process, and the ownership of rights in the standard. The term "standard" is sometimes restricted to technologies approved by formalized committees that are open to participation by all interested parties and operate on a consensus basis.
The definitions of the term open standard used by academics, the European Union and some of its member governments or parliaments such as Denmark, France, and Spain preclude open standards requiring fees for use, as do the New Zealand, South African and the Venezuelan governments.
Many definitions of the term standard permit patent holders to impose "reasonable and non-discriminatory licensing" royalty fees and other licensing terms on implementers or users of the standard. There are those in the open-source software community who hold that an "open standard" is only open if it can be freely adopted, implemented and extended. While open
standards or architectures are considered non-proprietary in the sense that the standard is either unowned or owned by a collective body, it can still be publicly shared and not tightly guarded. The typical example of “open source” that has become a standard is the personal computer originated by IBM and now referred to as Wintel, the combination of the Microsoft operating system and Intel microprocessor. There are three others that are most widely accepted as “open” which include the GSM phones (adopted as a government standard), Open Group which promotes UNIX and the like, and the Internet Engineering Task Force (IETF) which created the first standards of SMTP and TCP/IP. Buyers tend to prefer open standards which they believe offer them cheaper products and more choice for access due to network effects and increased competition between vendors.
Many specifications that are sometimes referred to as standards are proprietary and only available under restrictive contract terms (if they can be obtained at all) from the organization that owns the copyright on the specification. As such these specifications are not considered to be fully open. Joel West has argued that "open" standards are not black and white but have many different levels of "openness". Ultimately a standard need to be open enough that it will become adopted and accepted in the market, but still closed enough that firms can get a return on their investment in developing the technology around the standard. A more open standard tends to occur when the knowledge of the technology becomes dispersed enough that competition is increased and others are able to start copying the technology as they implement it. This occurred with the Wintel architecture as others were able to start imitating the software. Less open standards exist when a particular firm has much power (not ownership) over the standard, which can occur when a firm’s platform “wins” in standard setting or the market makes one platform most popular
Q2. Write a short note on IBM and open source?
Ans: Technology and the Internet revolution have made the world a smaller and "flatter" place. Global innovation continues to bring people around the world closer to one another, but we're now starting to realize that just being connected isn't enough.
Fortunately, a new revolution is beginning: one that holds significant potential. The planet is becoming smarter. Intelligence is being infused into the way the world literally works—into the systems, processes and infrastructure that enable physical goods to be developed, manufactured, bought and sold; that allow services to be delivered; that facilitate the movement of everything from money and oil to water and electrons. Ultimately, this will help to improve how billions of people work and live.
Open Source & Standards are key to making our planet smarter and improving the way we live and work.
Open Source: Open source in IT is software whose source code is published and made available to the public, enabling anyone to copy, modify and redistribute the source code without paying royalties or fees.
Standards: A standard is a specification that has been agreed upon by a community, through usage or declaration. Once established, any number of duplicates or variants can be made, while keeping the basic structure or function intact.
IBM is driving reforms for IP, Open Source & Standards. IBM is an industry leader helping governments move toward greater openness and innovation.
Q 3. Give brief introduction to linux.
Ans: Linux is a UNIX-base operating system. Its original creator was a Finnish student name Linus Torvalds, although being ‘open source’ it has change a great deal since its original conception. It belongs to nobody, and is free to download and use. Any changes to it are open for all to adopt, and as a result it has developed into a very powerful OS that is rapidly gaining in popularity worldwide, particularly among those seeking an alternative to Windows.
In 1991, hardware was expanding rapidly, and DOS was the king of operating systems. Software development was slower, and Macs, while better, were also much pricier than PCs. UNIX was growing, but at that time in its history the source code was jealously guarded and expensive to use.
Linus Torvalds was a Helsinki university student who liked playing around with software and computers, and in 1991 he announced the creation of a new core operating system that he had named Linux. It is now one of the most used systems for the PC, and is particularly suitable for businesses with small IT budgets. Linux is free to use and install, and is more reliable than almost all other systems, running for many months and even years without a reboot being necessary.
Advantages and Benefits of Linux
One of the significant benefits of open source software such as Linux is that because it has no owner, it can be debugged without resource to a license owner or software proprietor. Businesses therefore have the flexibility to do as they wish with the OS without having to worry about conforming to complex license agreements.
The major advantage of Linux is its cost: the core OS is free, while many software applications also come with a GNU General public License. It can also be used simultaneously by large numbers of users without slowing down or freezing and it is very fast. It is an excellent networking platform and performs at optimum efficiency even with little available hard disk space.
Linux also runs on a wide range of hardware types, including PCs, Macs, mainframes, supercomputers, some cell phones and industrial robots. Some prefer to dual-boot Linux and Windows while others prefer Linux and Mac OS. System76 machines come pre-installed with Linux in the form of Ubuntu, a Debian distribution of Linux. This is the most popular distribution of Linux for laptops.
Linux Vs Windows
The main benefits and advantages of Linux over other operating systems, particularly Microsoft Windows, are:
It is free to use and distribute.
Support is free through online help sites, blogs and forums.
It is very reliable – more so than most other operating systems with very few crashes.
A huge amount of free open source software has been developed for it.
It is very resistant to malware such as spyware, adware and viruses.
It runs in a wide variety of machines than cannot be updated to use newer Windows versions.
Since the source code is visible, ‘backdoors’ are easily spotted, so Linux offers greater security for sensitive applications.
Linux offers a high degree of flexibility of configuration, and significant customization is possible without modifying the source code.
The Linux operating system is widely use by both home and business users, and its usage is increasing daily. It is considered that Linux will eventually overtake Microsoft Windows as the most popular operating system, which could also open the door further for more free software such as Open Office, The Gimp, Paint, Thunderbird, Firefox and Scribus. It is easy to install and run alongside your existing operating system, so give it a try, because it is also easy to remove if you don’t like it – which is unlikely.
Q4. Brief introduction to PHP.
Ans: PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
Example #1 An introductory example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Example</title> </head> <body>
<?php echo "Hi, I'm a PHP script!"; ?>
</body></html>
Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages contain HTML with embedded code that does "something" (in this case, output "Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end processing instructions <?php and ?> that allow you to jump into and out of "PHP mode."
What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Although PHP's development is focused on server-side scripting, you can do much more with it.
Q5. What PHP can do?
Ans: Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.
There are three main areas where PHP scripts are used.
Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work. The PHP parser (CGI or server module), a web server and a web browser. You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming. See the installation instructions section for more information.
Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about Command line usage of PHP for more information.
Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit » its own website.
PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, IIS, and many others. And this includes any web server that can utilize the FastCGI PHP binary, like lighttpd and nginx. PHP works as either a module, or as a CGI processor.
So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object oriented programming (OOP), or a mixture of them both.
With PHP you are not limited to output HTML. PHP's abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content.
One of the strongest and most significant features in PHP is its support for a wide range of databases. Writing a database-enabled web page is incredibly simple using one of the database specific extensions (e.g., for mysql), or using an abstraction layer like PDO, or connect to any database supporting the Open Database Connection standard via the ODBC extension. Other databases may utilize cURL or sockets, like CouchDB.
PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects.
PHP has useful text processing features, which includes the Perl compatible regular expressions (PCRE), and many extensions and tools to parse and access XML documents. PHP standardizes all of the XML extensions on the solid base of libxml2, and extends the feature set adding SimpleXML, XMLReader and XMLWriter support.
And many other interesting extensions exist, which are categorized both alphabetically and by category. And there are additional PECL extensions that may or may not be documented within the PHP manual itself, like » XDebug.
Q6. How is linux better?
Ans: Linux Vs Windows
The main benefits and advantages of Linux over other operating systems, particularly Microsoft Windows, are:
It is free to use and distribute.
Support is free through online help sites, blogs and forums.
It is very reliable – more so than most other operating systems with very few crashes.
A huge amount of free open source software has been developed for it.
It is very resistant to malware such as spyware, adware and viruses.
It runs in a wide variety of machines than cannot be updated to use newer Windows versions.
Since the source code is visible, ‘backdoors’ are easily spotted, so Linux offers greater security for sensitive applications.
Linux offers a high degree of flexibility of configuration, and significant customization is possible without modifying the source code.
The Linux operating system is widely use by both home and business users, and its usage is increasing daily. It is considered that Linux will eventually overtake Microsoft Windows as the most popular operating system, which could also open the door further for more free software such as Open Office, The Gimp, Paint, Thunderbird, Firefox and Scribus. It is easy to install and run alongside your existing operating system, so give it a try, because it is also easy to remove if you don’t like it – which is unlikely
Surprise Test-1 (SF-1)
Q 1. Why C is called middle level language?Q2. What is latest version of c and its features? Q3. What is difference between pretested and post tested loop?Q4. Explain compilation process of C diagrammatically.Q5. What is ROM? Why it is called non volatile memory?
Surprise Test-2
Q1. What is difference b/w MS-DOS and Window Operating System?Q2 .What are conditional operator?Q3. What do you mean by loop and nested loop? Q4. What do you mean by keywords and identifiers?Q5. Explain ‘call by value’ and ‘call by reference’?Q6. What is difference b/w a pointer variable and reference variable?Q7 Explain the difference between structure and union with suitable example?
Q8. Write a note on file handling in C.
Q9.Does the C language provide array index out of bound check? Justify your answer.
Q10. What is a structure? How can you declare and initialize a structure?