Basics and
Introduction to C
1. Why are computers used? Brief their benefits.
Ans: Computers play a vital role in the socioeconomic progress of a country. Every nation is paying
great importance to computer literacy. Progress of individuals, surrounding region, nation and the world
is ensured only with the introduction and use of computers. In every occupation, computers are being
used increasingly. In every part of the world, computers are inducted to increase the overall productivity.
Moreover, the quality of the products due to the application of computers is substantially improved.
The impact of computers is very high on mass education, entertainment and productivity in all fields.
The use of computers reduces drastically the cost of production, saves a lot of time and ensures the best
quality.
In addition, the use of computer with some know-how (for the common users) and a lot of technical
innovations (by the developers), numerical problems, business transactions and scientific applications
can be computed in almost no time. A computer does various tasks based on the programs installed
in it. Intellectual computer is certainly a powerful gadget, but human intellectual capability is much
higher than that of a computer. Thus, computer does not have its own brain. Brainpower of computer
is limited. Thus, human intellectual power is further reinforced by the use of computers frequently in
the day-to-day life. By learning computer-programming languages, developing software packages and
understanding and developing hardware of computers, one can make life and the nation economically
prosperous.
2. Illustrate the functions of various parts of a computer.
Ans: Computer is a programmable electronic machine that accepts instructions and data through
input devices, manipulating data according to instructions and providing finally result to the output
device. The result can be stored in memory or sent to the output device. Figure 1.1 shows the block
diagram of a conventional computer.
1
M01_ITL-ESL4791_02_SE_C01.indd 3 12/22/2012 4:59:18 PM
II-4 Programming Concepts
Central
Processing
Unit
Input Output
Memory
Figure 1.1 Block Diagram of a Conventional Computer
Figure 1.2 shows a computer system containing a monitor, a keyboard and a rectangular box
comprising Central Processing Unit on the motherboard.
Figure 1.2 Computer System
A computer consists of the following main parts:
Input devices: They are used to accept the data and instructions into the computer. The various input
devices that can be used in a computer are keyboard, mouse, analog-to-digital converters, light pen,
track ball, optical character reader, scanner, etc.
Output devices: They are used to display the results on the screen or send the data to an output
device. The processed data is ultimately sent to the output device by the computer. The various out-
put devices that can be used in a computer are monitor, printer, LED, seven-segment display, D to A
converter, plotter, etc.
Memory:Memory is used to store the program. The memory is categorized into the following types:
1. primary memory and
2. secondary memory.
Primary memory: It is made from semiconductors. Further, there are two types of semiconductor
memories. They are:
1. RAM (random access memory) and
2. ROM (read-only memory).
Semiconductor memory is used for storing the instructions and data in the form of ones and zeros.
It can be called user’s memory or read–write memory. The processor first reads the instructions and data
from the primary memory (semiconductor memory). Then, it executes the instructions.
One more memory device used by a computer is called read-only memory (ROM). This contains
a fixed software program for providing certain operations. This is non-volatile memory. Its contents
cannot be eliminated when power supply goes off. The basic input–output system (BIOS) is a software
M01_ITL-ESL4791_02_SE_C01.indd 4 12/22/2012 4:59:19 PM
Basics and Introduction to C II-5
used to control various peripheral devices such as a keyboard, a monitor, a printer, a mouse and ports
including serial and parallel ports. In fact, this is an operating system. It is possible to access the users’
written programs, i.e., by loading a file, saving it and doing modifications to it in the later stage. As soon
as a personal computer is switched on, the software is booted from ROM. Thus, various functions are
assigned to all supporting peripherals of a central processing unit (CPU) and easy interactions are pro-
vided to the user by BIOS while booting the system.
Secondary memory: For storing a huge volume of data, secondary storage devices can be used. They are
optical disc, magnetic disc, tapes, etc.
Central processor unit:The heart of a computer system is a CPU. It comprises arithmetic and logical
unit, registers and control unit. The arithmetic and logical unit performs operations based on instruc-
tions. The control unit generates the timing and control signals for carrying out operations within the
processor. Registers are used for storing the results temporarily.
3. What is ANSI C standard?
Ans: For many years, there was no standard version of C language and the definition provided in the
reference manual was followed. Due to this reason, the portability feature of C language was not pro-
vided from one computer to another. To overcome this discrepancy, a committee was set up in the sum-
mer of 1983 to create a standard C version, which is popularly known as American National Standards
Institute (ANSI) standard. This committee had defined finally a standard C language. The standardiza-
tion process took about six years for defining the C language. The ANSI C standard was adopted in 1989
and its first copy of C language was introduced in the market in 1990. Thus, ANSI C is internationally
recognized as a standard C language. The purpose of this standard is to enhance the portability and
efficient execution of C language programs on different computers.
4. Explain the machine and assembly language concepts.
Ans: Machine language is a computer’s natural language, which can be directly understood by the
system. This language is machine dependent, i.e., it is not portable. A program written in 1s and 0s is
called a machine language. A binary code is used in a machine language for a specific operation. A set
of instructions in binary pattern is associated with each computer. It is difficult to communicate with
a computer in terms of 1s and 0s. Hence, writing a program with a machine language is very difficult.
Instead of using a string of binary bits in a machine language, programmers started using English-like
words as commands that can be easily interpreted by programmers. The program is in alphanumeric
symbols instead of 1s and 0s. The designer chooses easy symbols that are to be remembered by the
programmer, so that the programmer can easily develop the program in assembly language. The alpha-
numeric symbols are called mnemonics in the assembly language. The ADD, SUB, MUL, DIV, RLC and
RAL are some symbols called mnemonics.
5. Why C language is called middle-level language?
Ans: The C language combines the features of a high-level language and functionality-like assem-
bly languages. This language is designed for providing better programming efficiency (faster program
development) as compared to machine-oriented and machine efficiency languages (faster program
execution) and as compared to problem-oriented language. In C, one can develop a program fast and
execute fast. It is neither a low-level language nor a high-level language. However, it is a combination
of features of low- and high-level languages.
M01_ITL-ESL4791_02_SE_C01.indd 5 12/22/2012 4:59:19 PM
II-6 Programming Concepts
6. What is an algorithm? Explain in short.
Ans:  An algorithm is a well-organized, pre-arranged and well-defined textual computational module
that receives some value or set of values as input and provides a single value or a set of values as output.
These well-defined computational steps are arranged in a sequence, which processes the given input
into an output. Writing precise description of the algorithm using an easy language is most essential for
understanding the algorithm. An algorithm is said to be accurate and truthful only when it provides the
exact required output. Lengthy procedure is sub-divided into small parts and thus steps are made easy
to solve a given problem.
7. Mention and explain two types of algorithms.
Ans: Based on repetitive steps, an algorithm can further be classified into two types.
1. Direct  algorithm: In this type of algorithm, the number of iterations is known in advance.
For example, for displaying the numerical numbers from 1 to 10, the loop variable should be
initialized from 1 to 10. The statement would be as follows:
for(j = 1; j < = 10; j + + )
In the above statement, it is predicted that the loop will iterate 10 times.
2. Indirect algorithm: In this type of algorithm, steps are executed repetitively. Exactly how many
repetitions are to be made is unknown. For example, the repetitive steps are as follows:
(i) To find the first five Armstrong numbers from 1 to n, where n is a positive number. The n can
be from 2 to any finite value say 100.
(ii) To find the first three palindrome numbers from 1 to n, where n is a positive number. The n can
be from 2 to any finite value say 1000.
8. What are the functions of a compiler and an interpreter?
Ans:  Compilers are the translators, which translate all the instructions of the program into machine
codes. The program, which is to be translated, is called the source program; after translation, the object
code is generated. The source program is the input to the compiler. The object code is the output for the sec-
ondary storage device. The entire program will be read by the compiler first and generates the object code.
Interpreters also come in the group of translators. It helps the user to execute the source program
with a few differences as compared to compilers. The source program is just like English words in both
interpreters and compilers. The interpreter generates object codes for the source program. It reads the
program line by line; however, in compiler, the compiler reads the entire program, which then generates
the object codes. Interpreter directly executes the program from its source code. Due to this, every time
the source code should be inputted to the interpreter. In other words, each line is converted into the
object codes. It takes very less time for execution, because no intermediate object code is generated.
9. What is the difference between an interpreter and a compiler?
Ans: The interpreter executes the program line by line, whereas the compiler executes the complete
program at a time; that is, it first creates intermediate codes, then executes it.
10. What is meant by compilation? Explain in detail.
Ans: The source program is the input to the compiler. The object code is the output for the secondary
storage device. The entire program will be read by the compiler first and generates the object code. The
compiler displays the list of errors and warnings for the statements violating the syntax rules of the language.
Compilers may also have to link the subroutines of the program. The above procedure is called compilation.
M01_ITL-ESL4791_02_SE_C01.indd 6 12/22/2012 4:59:19 PM
Basics and Introduction to C II-7
11. Write the rules for writing a C program.
Ans: The rules for writing C programs are as follows:
1. Every program should have main() function as a starting point.
2. C statements should be terminated by a semicolon. The semicolon is used to mark the end of a
statement.
Example:
printf("Hello!");
It can also be used to separate the expressions in a for loop.
Example:
for(i = 0; i< = 10; i + +)
The C programmer can also use the comma operator to separate the expressions.
Example:
int a,b;
3. An unessential semicolon if placed by the programmer is treated as an empty statement.
4. All statements should be written in the lowercase letters. Generally, the uppercase letters are used
only for symbolic constants.
5. Blank spaces may be inserted between the words. This leads to improvement in the readability of
the statements. However, this is not applicable while declaring a variable, keyword, constant and
function.
6. It is not necessary to fix the position of statement in the program; i.e., a programmer can write the
statement anywhere between the two braces following the declaration part. The user can also write
one or more statements in one line separating them with a semicolon (;). Hence, it is often called a
free-form language. The following statements are valid.
a = b + c;
d = b*c;
or
a = b + c; d = b*c;
7. The opening and closing braces should be balanced, i.e., if opening braces are four, closing braces
should also be four.
12. Elaborate the different sections of a C program.
Ans: The sections in the C program are as follows:
Header  files  inclusion: In this section, all the header files that are needed are included using
#include directive.
Global declaration: In this section, all the global variables are declared, which can be used from
anywhere in the program.
main()function: This is the most important part of the program. The execution of every C program
starts from the main function. It may contain function prototypes, local variable declaration, executable
statements, comments, etc.
M01_ITL-ESL4791_02_SE_C01.indd 7 12/22/2012 4:59:19 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset