Sie sind auf Seite 1von 27

UNIT-I-INTRODUCTION

PART-B(16MARKS)
1. Define computer. Explain the characteristics briefly? (MAY 2009\FEB 2009)
Computer is an electronic device which is used to store the data, as per given
instructions it gives results quickly and accurately.
Characteristics of Computer
The characteristics of computers that have made them so powerful and universally useful are
speed, accuracy, diligence, versatility and storage capacity. Let us discuss them briefly.

Speed

Computers work at an incredible speed. A powerful computer is capable of performing about 3-4
million simple instructions per second.

Accuracy

In addition to being fast, computers are also accurate. Errors that may occur can almost always
be attributed to human error (inaccurate data, poorly designed system or faulty
instruction/programs written by the programmer)

Diligence

Unlike human beings, computers are highly consistent. They do not suffer from human traits of
boredom and tiredness resulting in lack of concentration. Computers, therefore, are better than
human beings in performing voluminous and repetitive jobs.

Versatility

Computers are versatile MAChines and are capable of performing any task as long as it can be
broken down into a series of logical steps. The presence of computers can be seen in almost
every sphere Railway/Air reservation, Banks, Hotels, Weather forecasting and many more.

Storage Capacity

Todays computers can store large volumes of data. A piece of information once recorded (or
stored) in the computer, can never be forgotten and can be retrieved almost instantaneously.
2. Explain briefly the developments in computer technology starting from a simple
Calculating MAChine to the first computer
Calculating MAChine:
A computer is a MAChine that works with data and information in the form of numbers.
People from the beginning of time, and throughout the years, have invented and continue to
invent things that help them count. Caveman counted with the only counting tools they knew,
their fingers and toes. These were considered the first counting tools. Soon man realized that
other objects needed to be used to keep up with larger numbers. Some of the other counting tools

that have been used throughout time have been stones, knots on ropes (quipu), and notches on
sticks, notches on bones, tally sticks, to name just a few. People used these counting tools to
count their possessions and also to keep tract of the passing of time.
Napier bones:
The oldest known objects used to represent numbers are bones with notches carved into
them. These bones, which were discovered in western Europe, date from the Aurignacian period
20,000 to 30,000 years ago and correspond to the first appearance of Cro-Magno man.Counting
boards and counting tablets were also used to represent everyday calculations such as goods
bought and sold.
Slide Rules:
The slide rule is used primarily for multiplication and division, and also for functions
such as roots, logarithms and trigonometry, but is not normally used for addition or subtraction.
Though similar in name and appearance to a standard ruler, the slide rule is not ordinarily used
for measuring length or drawing straight lines. Slide rules exist in a diverse range of styles and
generally appear in a linear or circular form with a standardized set of markings (scales) essential
to performing mathematical computations.
Pascals Addition and subtracting MAChine:
The Pascaline is known as the first mechanical and automatic calculator. Pascal invented
the Pascaline to help make his father's job as a tax accountant easier. The MAChine is sometimes
called the La Pascaline or Pascal's MAChine. The Pascaline never became popular. First of all,
the MAChine broke often and its inventor was the only person who could fix it. Second, it was
slow. Third, clerks would not use it: They were afraid it might replace them at their jobs. The
Pascaline was a wooden box that could only add and subtract by means of a series of gears and
wheels. When each wheel rotated one revolution, it would then turn the neighboring wheel. On
top of the wheels were a series of windows through which the totals could be read. About 50
models were constructed and were made of wood, ivory, ebony, and copper.
Leibnizs Multiplication and division MAChine:
In 1673, German inventor Gottfried Leibniz perfected the Leibniz Calculator. Leibniz entered a
university at fifteen years of age and received his bachelor's degree at seventeen. This MAChine
is sometimes called The Stepped Reckoner. The Liebniz was also a calculating MAChine, but
much superior to that of the Pascaline. It could do more than just add and subtract. The Leibniz
Calculator could also multiply, divide, and find square roots of numbers. It too was mechanical
and worked by hand. A crank was added to speed up the work of this calculator. It was used by
mathematicians and bookkeepers.Mr. Leibniz believed that it did not make sense for men to
spend hours and hours doing mathematical calculations when he could invent a MAChine that

would work much faster. Would you rather add a long list of numbers with a pencil and paper or
use a calculator.
Charles Babbage & his Engines:
In the early 1820s, an English mathematician by the name Charles Babbage, designed a
computing MAChine called the Difference Engine. This MAChine was to be used in the
calculating and printing of simple math tables. In the 1830s, he designed a second computing
MAChine called the Analytical Engine. This MAChine was to be used in calculating complicated
problems by following a set of instructions.
Analytical Engine:
The Analytical Engine was a mechanical computer that can solve any mathematical
problem. It uses punch-cards similar to those used by the Jacquard loom and can perform simple
conditional operations.
Difference Engine:
However, neither of these MAChines were ever finished because the
technology at the time was not advanced enough, and both of his projects
lacked financial funding. The computing MAChines made in the 1900s, and
even those today are based on the designs of the Difference Engine and the
Analytical Engine. This is why Charles Babbage is known as the "Father of
Computers."
Herman Hollerith & his Tabulating MAChine
An American inventor by the name of Herman Hollerith wanted to speed up the work
involved in taking the government census. In 1890, 50 years after Charles Babbage's death,
Hollerith invented a MAChine called the tabulating MAChine, using notes that were left by
Babbage. Prior to this invention it took nearly eight years to count everyone in the United States
and add up all the information about where people lived, their ages, and what their jobs were.
The Tabulating MAChine used punched cards to record and sort data or information. Each hole
punched meant something. If a hole had been punched, a pin would pass through it to make an
electrical contact with mercury in a cup below. This turned motors that moved numbers that
counted. Approximately 65 cards could be passed through this computer in a minute, and in 1890
it took only 2.5 years to complete the U.S. Census.
2. Explain in detail the different generation of computers.

Computers are such an integral part of our everyday life now most people take them
and what they have added to life totally for granted. Even more so the generation who have
grown from infancy within the global desktop and laptop revolution since the 1980s.The
history of the computer goes back several decades however and there are five definable
generations of computers. Each generation is defined by a significant technological development
that changes fundamentally how computers operate leading to more compact, less expensive,
but more powerful, efficient and robust MAChines.
1940 1956: First Generation Vacuum Tubes
These early computers used vacuum tubes as circuitry and magnetic drums for memory.
As a result they were enormous, literally taking up entire rooms and costing a fortune to run.
These were inefficient materials which generated a lot of heat, sucked huge electricity and
subsequently generated a lot of heat which caused ongoing breakdowns.
These first generation computers relied on MAChine language (which is the most basic
programming language that can be understood by computers). These computers were limited to
solving one problem at a time. Input was based on punched cards and paper tape. Output came
out on print-outs. The two notable MAChines of this era were the UNIVAC and ENIAC
MAChines the UNIVAC is the first every commercial computer which was purchased in 1951
by a business the US Census Bureau.
1956 1963: Second Generation Transistors
The replacement of vacuum tubes by transistors saw the advent of the second generation
of computing. Although first invented in 1947, transistors werent used significantly in
computers until the end of the 1950s. They were a big improvement over the vacuum tube,
despite still subjecting computers to damaging levels of heat. However they were hugely superior
to the vacuum tubes, making computers smaller, faster, cheaper and less heavy on electricity use.
They still relied on punched card for input/printouts.
The language evolved from cryptic binary language to symbolic (assembly) languages.
These meant programmers could create instructions in words. About the same time high level
programming languages were being developed (early versions of COBOL and FORTRAN).
Transistor-driven MAChines were the first computers to store instructions into their memories
moving from magnetic drum to magnetic core technology. The early versions of these
MAChines were developed for the atomic energy industry.
1964 1971: Third Generation Integrated Circuits
By this phase, transistors were now being miniaturized and put on silicon chips (called
semiconductors). This led to a massive increase in speed and efficiency of these MAChines.

These were the first computers where users interacted using keyboards and monitors which
interfaced with an operating system, a significant leap up from the punch cards and printouts.
This enabled these MAChines to run several applications at once using a central program which
functioned to monitor memory.
As a result of these advances which again made MAChines cheaper and smaller, a new
mass market of users emerged during the 60s.
1972 2010: Fourth Generation Microprocessors
This revolution can be summed in one word: Intel. The chip-maker developed the Intel
4004 chip in 1971, which positioned all computer components (CPU, memory, input/output
controls) onto a single chip. What filled a room in the 1940s now fit in the palm of the hand. The
Intel chip housed thousands of integrated circuits. The year 1981 saw the first ever computer
(IBM) specifically designed for home use and 1984 saw the MACintosh introduced by Apple.
Microprocessors even moved beyond the realm of computers and into an increasing number of
everyday products.
The increased power of these small computers meant they could be linked, creating
networks. Which ultimately led to the development, birth and rapid evolution of the Internet?
Other major advances during this period have been the Graphical user interface (GUI), the
mouse and more recently the astounding advances in lap-top capability and hand-held devices.

2010- : Fifth Generation Artificial Intelligence


Computer devices with artificial intelligence are still in development, but some of these
technologies are beginning to emerge and be used such as voice recognition. AI is a reality made
possible by using parallel processing and superconductors. Leaning to the future, computers will
be radically transformed again by quantum computation, molecular and nano technology. The
essence of fifth generation will be using these technologies to ultimately create MAChines which
can process and respond to natural language, and have capability to learn and organise
themselves.
3. Describe the different classification of computers.
It can classify computers on the basis of size as below:

Super computer
Super computer is the fastest, most expensive, big in size, and most powerful computer that can
perform multiple tasks within no second. It has multi-user, multiprocessing, very
highefficiency and large amount of storage capacity. It is called super computer because it can
solve difficult and complex problem within a nano second.
Application
o
o
o
o
o
o

Used to forecast the weather and global climates


Used in military research and defense systems
In automobile, aircraft, and space craft designing
Used in seismography, plasma and nuclear research
Study of genetic engineering
Digital film recording

Example
c-DAC (center for development of advanced computer) of INDIA has developed PARAM series
of super computer. Anurag is also indian super computer. Other super computers are cray
xmp/14, CDC-205 etc. Mr. Seymour cray was a pioneer person in the field of supercomputer
production. He had developed the first super computer cray-1 in 1976.
Mainframe computer
Mainframe computer is the large sized computer that covers about 1000 sq feet. It is
general purpose computer that is designed to process large amount of data with very high speed.
It accepts large amount of data from different terminals and multiple users and process them at
same time. More than 100 users are allowed to work in this system. It is applicable for large
organization with multi-users for example: large business organization, department of
examinations, industries and defense to process data of complex nature. It uses several cpu for
data processing.
Application areas
o
o
o
o
o
o
o

Government and civilian


Credit card processing
Back account management
Marketing
Business data processing in large organization
Air traffic control system
Industrial design

Example
IBM s/390, IBM s/709, ICL 39, CDC 6600
Minicomputer
Mini computers are medium sized computer. So, these are popular as middle ranged
computer. It is also multiple user computer and supports more than dozen of people at a time. It
is costlier than microcomputer.
It is also used in university, middle range business organizations to process complex data. It is
also used in scientific research, instrumentation system, engineering analysis, and industrial
process monitoring and control etc.
Example
languages, multimedia, graphics, 3d graphics and games. These are popular among students,
professionals and home users due to small size, low price and low maintenance.
PDP-11, vax etc.
Microcomputer
Most popular general purpose computers which are mostly used on day to day work are
microcomputers. These are popular as home pc or personal computer (pc) because these are
single user computers and mostly used for personal use and application. These support many
higher level application cost and easy in operation.
Example
IBM PCs, apple MAC, IBM ps/2, all computer available with pentium models etc.

4.Explain the organization of a computer.


A major defining point in the history of computing was the realisation in 19441945 that
data and instructions to manipulate data were logically the same and could be stored in the same
place. The computer design built upon this principle, which became known as the von Neumann
Architecture, is still the basis for computer today. Although the name honours John von
Neumann, a brilliant mathematician who worked on the construction of the atomic bomb, the
idea probably originated with J. Presper Echkert and John Mauchly, two other early pioneers
who worked on the ENIAC at the Moore School at the University of Pennsylvania during the
same time period.

Von Neumann Architecture


Another major characteristic of the von Neumann architecture is that the units that process
information are separate from the units that store information. This characteristic leads to the
following components of the von Neumann architecture.

The memory unit that holds both data and instructions.


The arithmetic/logic gate unit that is capable of performing arithmetic and logic
operations on data.

The input unit that moves data from the outside world into the computer.

The output unit that moves results from inside the computer to the outside world.

The control unit that acts as the stage unit to ensure that all the other components act in
concert.

Memory
Memory is a collection of cells, each with a unique physical address. We use the generic
word cell here rather than byte, because the number of bits in each addressable location, called

the memory's addressability, varies from one machine to another. Today, most computers are
byte addressable.
To fully illustrate the concept of memory, take a computer with 4GB of RAM as an
example. The memory consists of 4 230 bytes, which means each byte of the computer is
uniquely addressable, and the addressability of the machine is 8 bits. The cells in memory are
numbered consecutively beginning with 0. For example, if the addressability is 8, and there are
256 cells of memory, the cells would be addressed as follows:
The Arithmetic/Logic Unit (ALU) is capable of performing basic arithmetic operations
such as adding, subtracting, multiplying, and dividing two numbers. This unit is also capable of
performing logical operations such as AND , OR , and NOT . The ALU operates on words, a
natural unit of data associated with a particular computer design. Historically, the word length of
a computer has been the number of bits processed at once by the ALU. However, the current
Intel line of processors has blurred this definition by defining the word length to be 16 bits. The
processor can work on words (of 16 bits), double words (32 bits), and quadwords (64 bits). In the
rest of this wiki, when referring to word, it will be of the historical nature aforementioned.
Most modern ALUs have a small number of special storage units called Registers. These
registers contain one word and are used to store information that is needed again immediately.
For example in the calculation of 1 (2 + 3). 2 is first added to 3 and the result is multiplied by
1. Rather than storing the result of adding 2 and 3 in memory and then retrieving it to multiply it
by 1, the result is left in a register and the contents of the register is multiplied by 1. Access to
registers is much faster than access to memory locations.
Input/Output Units
All of the computing power in the world would not be useful if one could not input values into
the calculations from the outside or report to the outside the results of said calculations. Input
and output units are the channels through which the computer communicates with the outside
world.
An Input Unit is a device through which data and programs from the outside world are entered
into the computer. The first input units interpreted holes punched on paper tape or cards.
Modern-day input devices, however, include, but are not limited to; keyboards, mice, cameras
(also known as, simply, webcams), and scanning devices.
An Output Unit is a device through which results stored in the computer memory are made
available to the outside world. Examples include printers and screen monitors.

Control Unit
The Control Unit is the organising force in the computer, for it is in charge of the Fetch-Execute
Cycle. There are two special registers in the control unit. The Instruction Register (IR) contains
the instruction that is being executed, and the Program Counter (PR) contains the address of the
next instruction to be executed. Because the ALU and the control unit work so closely together
they are often thought of as one unit called the Central Processing Unit (CPU).

Above is a simplified view of the flow of information through the parts of a von Neumann
machine. The parts are connected to one another by a collection of wires called a bus, through
which data travels in the computer. Each bus carries three kinds of information; address, data,
and control. An address is used to select the memory location or device to which data will go, or
from which it will be taken. Data then flows over the bus between CPU, memory, and I/O
Devices. The control information is used to manage the flow of addresses and data. For example,
a control signal will typically be used to determine the direction in which the data is flowing
either to or from the CPU. The Bus Width is the number of bits that it can transfer
simultaneously. The wider the bus, the more address or data bits it can move at once.
RAM and ROM
Describe primary memory.
RAM stands for Random-Access Memory. RAM is memory in which each cell (usually a byte)
can be directly accessed. Inherent in the idea of being able to access each location is the ability
to change the contents of each location. That is, storing something else into that place can change
the bit pattern in each cell.
In addition to RAM, most computers contain a second kind of memory called ROM. ROM
stands for Read-Only Memory. The contents in locations in ROM cannot be changed. Their
contents are permanent and cannot be altered by a second operation. Placing the bit pattern in

ROM is called burning. The bit pattern is burnt either at the time the ROM is manufactured or at
the time the computer parts are assembled.
RAM and ROM are differentiated by a very basic property; RAM is volatile, and ROM is not.
This means that RAM does not retain its bit configuration when the power is turned off, but
ROM does. Because ROM is stable and cannot be changed, it is used to store the instructions
that the computer needs to start itself. Frequently used software is also stored in ROM so that the
system does not have to read the software each time the machine is turned on. Main memory
usually contains some ROM along with the general-purpose RAM.
Secondary Storage Devices
Identify the need for persistent storage.
An input device is the means by which data and programs are entered into the computer and
stored into memory. An output device is the means by which results are sent back to the user.
Because most of main memory is volatile and limited, it is essential that there be other types of
storage devices where programs and data can be stored when they are no longer being processed
or when the machine is not turned on. These other types of storage devices (other than that of
main memory) are called secondary or auxiliary storage devices. Because data must be read
from them and written to them, each storage device is also an input and an output device.
Examples of secondary storage devices include;

Magnetic Tape,

Magnetic Disks,

CDs and DVDs,

Flash Drives,

External Hardrives

5. Explain the various types of computer memory.


Memory is major part of computers that categories into several types. Memory is best
storage part to the computer users to save information, programs and etc, The computer
memory offer several kinds of storage media some of them can store data temporarily and some

them can store permanently. Memory consists of instructions and the data saved into computer
through Central Processing Unit (CPU).

Types of Computer Memorys:


Memory is the best essential element of a computer because computer cant perform simple
tasks. The performance of computer mainly based on memory and CPU. Memory is internal
storage media of computer that has several names such as majorly categorized into two types,
Main memory and Secondary memory.
1. Primary Memory / Volatile Memory.
2. Secondary Memory / Non Volatile Memory.
1. Primary Memory / Volatile Memory:
Primary Memory also called as volatile memory because the memory cant store the data
permanently. Primary memory select any part of memory when user want to save the data in
memory but that may not be store permanently on that location. It also has another name i.e.
RAM.

Random Access Memory (RAM):


The primary storage is referred to as random access memory (RAM) due to the random selection
of memory locations. It performs both read and write operations on memory. If power failures
happened in systems during memory access then you will lose your data permanently. So, RAM
is volatile memory. RAM categorized into following types.

DRAM
SRAM
DRDRAM

2. Secondary Memory / Non Volatile Memory:


Secondary memory is external and permanent memory that is useful to store the external storage
media such as floppy disk, magnetic disks, magnetic tapes and etc cache devices. Secondary
memory deals with following types of components.
Read Only Memory (ROM) :
ROM is permanent memory location that offer huge types of standards to save data. But it work
with read only operation. No data lose happen whenever power failure occur during the ROM
memory work in computers.
ROM memory has several models such names are following.
1. PROM: Programmable Read Only Memory (PROM) maintains large storage media but cant
offer the erase features in ROM. This type of RO maintains PROM chips to write data once and
read many. The programs or instructions designed in PROM cant be erased by other programs.
2. EPROM : Erasable Programmable Read Only Memory designed for recover the problems of
PROM and ROM. Users can delete the data of EPROM thorough pass on ultraviolet light and it
erases chip is reprogrammed.
3. EEPROM: Electrically Erasable Programmable Read Only Memory similar to the EPROM
but it uses electrical beam for erase the data of ROM.
Cache Memory: Mina memory less than the access time of CPU so, the performance will
decrease through less access time. Speed mismatch will decrease through maintain cache
memory. Main memory can store huge amount of data but the cache memory normally kept
small and low expensive cost. All types of external media like Magnetic disks, Magnetic drives
and etc store in cache memory to provide quick access tools to the users.

7.Explain the program development life cycle in detail.


This stage is the updating and correcting of the program to account for changing
conditions or field experience. Proper testing and documentation should significantly reduce the
frequency and extent of required maintenance. Unlike student programs thatv used for a long
time. Changes may occur due to:

Newly discovered bugs.

Specification changes.

Specification expansion.

New equipment. The costs involved in program maintenance are usually grossly underestimated
by most programmers. It has been studied that in a typical programming environment, over 50%
of the time is spent on maintaining the existing programs. So, it becomes really necessary to
reduce the costs and the time spent on maintenance. This can be done by the use of the following
steps:

Clarity and readability of code.

Portability and generality.

Structured code.

Modularity.

Debugging and testing.

Documentation.

Extention And Redesign:


This stage is the extension of the program to solve problems beyond those described in initial
problem definition. Obviously designers want to take advantage of programs developed for
previous tasks.
Designers should not consider any task in complete isolation from those that occur subsequently.
Redesign may involve adding new features or meeting new requirements. Such redesign should
proceed through the previously mentioned stages of software development. The process may also
involve making a program meet critical time or memory requirements. When relatively small
increase in speed or reduction in memory usage is needed, a program can often be reorganized to
meet the requirement. Program structure may have to be sacrificed. The new program must be

carefully documented, since its working will seldom be obvious. Such are organization may
require a large amount of programmers time and should be avoided when possible. Enormous
gains cannot be expected from program optimization. Unless the program is very poorly written,
speed increase or memory reduction larger than 25% is rare.
8. Explain the need for an algorithm and highlight its advantages. Write an algorithm
to find the greatest among three numbers.

An algorithm is an effective method for solving a given problem.


It is sequence of instructions that tells how the problem can be addressed and solved.
Algorithm is the basis for any programming and falls under the computer science.
However it is not mandatory as algorithm can be used in daily life also,just like making
tea. You think algorithm for making tea.
Every program is structured and must follow the specified guidelines. This is structural
behavior.
But algorithm gives the steps for the program. With logical induction, we can find the
solution, but to do in program we need to use the appropriate algorithm.

Advandages
To write the logic and method(s) to solve the problem in the procedural steps is called
Algorithm. Algorithm in a step by step procedure to solve a given problem.
1) Algorithms are independent of any computer language.
2) Algorithms are easy
3) To debug, since every step has got its own logical sequence.
4) Algorithms can be easily converted into flowcharts and then into computer programs
Write an algorithmto find the greatest among three numbers.
Input: Three numbers a, b, and c
Output: x, the largest of a, b, and c
procedure max(a, b, c)
x := a
if b>x
then x := b
if c>x
then x :=
return(x)

end max.
9. Mention the guidelines in detail while drawing a flowchart with examples and list
out the merits and demerits of flowcharting.

The following are some guidelines in flow charting:


In drawing a proper flow chart, all necessary requirements should be listed out in logical
order.
The flowchart should be clear, neat and easy to follow. There should not be any room for
ambiguity in understanding the flow chart.
The usual direction of the flow of a procedure or system is from left to right or top to
bottom.
Only one flow line should come out from a process symbol.
Only one flow line should enter a decision symbol, but two or three flow lines, one for
each possible answer, should leave the decision symbol.
Only one flow line is used in conjunction with terminal symbol.
Write within standard flow chart symbols briefly. As necessary, you can use the
annotation symbol to describe data or computational steps more clearly.
If the flowchart becomes complex, it is better to use connector symbols to reduce the
number of flow lines. Avoid the intersection of flow lines if you want to make it more effective
and better way of communication.
Ensure that the flowchart has a logical start and finish.
It is useful to test the validity of the flowchart by passing through it with a simple test
data.
Advantages Of Using Flowcharts:
Communication: Flowcharts are better way of communicating the logic of a system to all
concerned or involved.
Effective analysis: With the help of flowchart, problem can be analysed in more effective way
therefore reducing cost and wastage of time.
Proper documentation: Program flowcharts serve as a good program documentation, which is
needed for various purposes, making things more efficient.
Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and
program development phase.
Proper Debugging: The flowchart helps in debugging process.
Efficient Program Maintenance: The maintenance of operating program becomes easy with the
help of flowchart. It helps the programmer to put efforts more efficiently on that part
Disadvantages Of Using Flowcharts:
Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart
becomes complex and clumsy. This will become a pain for the user, resulting in a waste of time
and money trying to correct the problem
Alterations and Modifications: If alterations are required the flowchart may require re-drawing

completely. This will usually waste valuable time.


Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a
problem.
Example:

UNIT-II-C PROGRAMMING BASICS


1. Explain in detail the structure of a C program with an example.

1. Documentation section: The documentation section consists of a set of comment lines


giving the name of the program, the author and other details, which the programmer
would like to use later.
2. Link section: The link section provides instructions to the compiler to link functions from
the system library such as using the#include directive.
3. Definition section: The definition section defines all symbolic constants such using
the #define directive.
4. Global declaration section: There are some variables that are used in more than one
function. Such variables are called global variables and are declared in the global
declaration section that is outside of all the functions. This section also declares all
the user-defined functions.
5. main () function section: Every C program must have one main function section. This
section contains two parts; declaration part and executable part
1. Declaration part: The declaration part declares all the variables used in the
executable part.

2. Executable part: There is at least one statement in the executable part. These two
parts must appear between the opening and closing braces. The program
execution begins at the opening brace and ends at the closing brace. The closing
brace of the main function is the logical end of the program. All statements in the
declaration and executable part end with a semicolon.
6. Subprogram section: If the program is a multi-function program then the subprogram
section contains all the user-defined functions that are called in the main () function.
User-defined functions are generally placed immediately after the main () function,
although they may appear in any order.
All section, except the main () function section may be absent when they are not required
2. Explain in detail about the constants, expressions and statements in C.
Variables
Variable names in C can consist of letters and numbers in any order, except that the first
character must be a letter. Names are case sensitive, so upper- and lower-case letters are not
interchangeable. The underscore character (_) can also be included in variable names, and is
treated as a letter. There is no restriction on the length of names in C. Of course, variable names
are not allowed to clash with keywords that play a special role in the C language, such as int,
double, if, return, void, etc. The following are examples of valid variable names in C:
x c14 area electron mass TEMPERATURE
The C language supports a great variety of different data types. However, the two data types
which occur most often in scientific programs are integer, denoted int, and floating-point,
denoted double. (Note that variables of the most basic floating-point data type float are not
generally stored to sufficient precision by the computer to be of much use in scientific
programming.) The data type (int or double) of every variable in a C program must be
declared before that variable can appear in an executable statement.
Integer constants in C are denoted, in the regular fashion, by strings of arabic numbers: e.g.,
0 57 4567 128933
Floating-point constants can be written in either regular or scientific notation: e.g.,
0.01 70.456 3e+5 .5067e-16
Strings are mainly used in scientific programs for data input and output purposes. A string
consists of any number of consecutive characters (including blanks) enclosed in double quotation
marks: e.g.,

"red" "Austin TX, 78723" "512-926-1477"


Line-feeds can be incorporated into strings via the escape sequence \n: e.g.,
"Line 1\nLine 2\nLine 3"
The above string would be displayed on a computer terminal as
Line 1
Line 2
Line 3
A declaration associates a group of variables with a specific data type. As mentioned previously,
all variables must be declared before they can appear in executable statements. A declaration
consists of a data type followed by one or more variable names, ending in a semicolon. For
instance,
int a, b, c;
double acc, epsilon, t;
In the above, a, b, and c are declared to be integer variables, whereas acc, epsilon, and t are
declared to be floating-point variables.
A type declaration can also be used to assign initial values to variables. Some examples of how
to do this are given below:
int a = 3, b = 5;
double factor = 1.2E-5;
Here, the integer variables a and b are assigned the initial values 3 and 5, respectively, whereas
the floating-point variable factor is assigned the initial value .
Note that there is no restriction on the length of a type declaration: such a declaration can even
be split over many lines, so long as its end is signaled by a semicolon. However, all declaration
statements in a program (or program segment) must occur prior to the first executable statement.
Expressions and statements
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. Thus, the expression is equivalent to
j=j+1
The increment (by unity) operator ++ is called a unary operator, because it only possesses one
operand.
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. For example:
a = 6;
c = a + b;
++j;
The first two expression statements both cause the value of the expression on the right of the
equal sign to be assigned to the variable on the left. The third expression statement causes the
value of j to be incremented by 1. Again, there is no restriction on the length of an expression
statement: such a statement can even be split over many lines, so long as its end is signaled by a
semicolon.
A compound statement consists of several individual statements enclosed within a pair of
braces { }. The individual statements may themselves be expression statements, compound
statements, or control statements. Unlike expression statements, compound statements donot end
with semicolons. A typical compound statement is shown below:
{
pi = 3.141593;
circumference = 2. * pi * radius;
area = pi * radius * radius;
}
This particular compound statement consists of three expression statements, but acts like a single
entity in the program in which it appears.
A symbolic constant is a name that substitutes for a sequence of characters. The characters may
represent either a number or a string. When a program is compiled, each occurrence of a
symbolic constant is replaced by its corresponding character sequence. Symbolic constants are
usually defined at the beginning of a program, by writing
#define NAME text
where NAME represents a symbolic name, typically written in upper-case letters,
and text represents the sequence of characters that is associated with that name. Note
that text does not end with a semicolon, since a symbolic constant definition is not a true C

statement. In fact, during compilation, the resolution of symbolic names is performed (by the C
preprocessor) before the start of true compilation. For instance, suppose that a C program
contains the following symbolic constant definition:
#define PI 3.141593
Suppose, further, that the program contains the statement
area = PI * radius * radius;
During the compilation process, the preprocessor replaces each occurrence of the symbolic
constant PI by its corresponding text. Hence, the above statement becomes
area = 3.141593 * radius * radius;
Symbolic constants are particularly useful in scientific programs for representing constants of
nature, such as the mass of an electron, the speed of light, etc. Since these quantities are fixed,
there is little point in assigning variables in which to store them.
3.Discuss about the various data types in C.

In C programming, variables or memory locations should be declared before it can be used.


Similarly, a function also needs to be declared before use.
Data types simply refers to the type and size of data associated with variables and functions.
Data types in C
1. Fundamental Data Types
o Integer types
o Floating type

o Character type
2. Derived Data Types
o Arrays
o Pointers
o Structures
o Enumeration
Integer data types
Integers are whole numbers that can have both positive and negative values, but no decimal
values. Example: 0, -5, 10
In C programming, keyword int is used for declaring integer variable. For example:

int id;

Here, id is a variable of type integer.


You can declare multiple variable at once in C programming. For example:

int id, age;

The size of int is either 2 bytes(In older PC's) or 4 bytes. If you consider an integer having size of
4 byte( equal to 32 bits), it can take 232 distinct states as: -231,-231+1, ...,-2, -1, 0, 1, 2, ..., 231-2,
231-1
Similarly, int of 2 bytes, it can take 216 distinct states from -215 to 215-1. If you try to store larger
number than 231-1, i.e,+2147483647 and smaller number than -231, i.e, -2147483648, program
will not run correctly.

Floating types
Floating type variables can hold real numbers such as: 2.34, -9.382, 5.0 etc. You can declare a
floating point variable in C by using either float or double keyword. For example:

float accountBalance;
double bookPrice;

Here, both accountBalance and bookPrice are floating type variables.


In C, floating values can be represented in exponential form as well. For example:

float normalizationFactor = 22.442e2;

Difference between float and double


The size of float (single precision float data type) is 4 bytes. And the size ofdouble (double
precision float data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas
the precision of double is 14 digits.
Character types
Keyword char is used for declaring character type variables. For example:

char test = 'h'

Here, test is a character variable. The value of test is 'h'.


The size of character variable is 1 byte.
C Qualifiers

Qualifiers alters the meaning of base data types to yield a new data type.
Size qualifiers
Size qualifiers alters the size of a basic type. There are two size qualifiers, longand short. For
example:

long double i;

The size of float is 8 bytes. However, when long keyword is used, that variable becomes 10
bytes.
If you know that the value of a variable will not be large, short can be used.
Sign qualifiers
Integers and floating point variables can hold both negative and positive values. However, if a
variable needs to hold positive value only, unsigned data types are used. For example:

// unsigned variables cannot hold negative value


unsigned int positiveInteger;

There is another qualifier signed which can hold both negative and positive only. However, it is
not necessary to define variable signed since a variable is signed by default.
An integer variable of 4 bytes can hold data from -231 to 231-1. However, if the variable is defined
as unsigned, it can hold data from 0 to 232-1.
It is important to note that, sign qualifiers can be applied to int and char types only.
Constant qualifiers
An identifier can be declared as a constant. To do so const keyword is used.

const int cost = 20;

The value of cost cannot be changed in the program.


Volatile qualifiers
A variable should be declared volatile whenever its value can be changed by some external
sources outside the program. Keyword volatile is used for creating volatile variables.

4. Describe the various types of operators in C language along with its priority.
Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated. Certain operators have higher precedence than others; for example, the
multiplication operator has a higher precedence than the addition operator.
For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
Category

Operator

Associativity

Postfix

() [] -> . ++ - -

Left to right

Unary

+ - ! ~ ++ - - (type)* & sizeof

Right to left

Multiplicative

*/%

Left to right

Additive

+-

Left to right

Shift

<< >>

Left to right

Relational

< <= > >=

Left to right

Equality

== !=

Left to right

Bitwise AND

&

Left to right

Bitwise XOR

Left to right

Bitwise OR

Left to right

Logical AND

&&

Left to right

Logical OR

||

Left to right

Conditional

?:

Right to left

Assignment

= += -= *= /= %=>>= <<= &= ^= |=

Right to left

Comma

Left to right

Das könnte Ihnen auch gefallen