Chapter
Chapter
COM TO
GET NOTE* OF ANY CLA** TO
GET HIGH MARK*
SHORT .žND LONFì QUESTIONS
Q1. Define œmputer progamming.
Ans: Computer Programming:
Computer programming is the process of writing a computer program in
computer language to solve a particular problem.
Computer program controls the operation of a computer and it is
developed in a computer language to perform a task Computer languages are also
known as programming languages
Q2. Define Programming Language. Explain low level and high level
languages
OR
Explain popular programming languages and their uses.
Ans: Programming Languages:
A programming language is a language which is understood by computer It
is designed to give instructions to a computer to perform a specific task. It is used to
write computer programs.
Classifiœtion of Programming Languages:
Programming languages can be classified into two categories. that is, low
level languages and high level languages.
i. Lęw Level Lanquąqes:
Low level language is machine-ońented language To understand low level
language. detailed knowledge of internal working of computer is required Low level
languages include mechJne čnztj/uage and assembly čaztguoge.
clawifiœtion of Low Level Language:
t uachine Language:
Pr ogramming language that is directly understood by computer hardware is
known as machine language Machine language is associated with a rchitecture of
COmputer Therefore, programs written in machine language for one computer will
not work on another because of design differences. It consists of zeroes and ones It
is almost impossible for humans to use machine language because it entirely
consists of numbers Therefore. practically no programming is done in machine
language Instead. assembly languages and high level languages are used
t assembly Language:
Assembly language consists of symbolic codes or abbreviations known as
mnemonics It was developed to make computer programming easier than machine
language The abbreviations used in assembly language make it easier to learn and
write programs compared to machine language A program written in assembly
language must be converted into machine language before it is executed by
assembl er is used to translate assembly iangUag O'
A compiler is a computer
Software that translate s language program
C
(8OUfC8 program) into machine code (object program) that can be understood and
executed by the computer as shown in Fig. It also detects syqtax errors in the
source program and gives hints IO the pfogrammer to correct them A compiler will
only create object program if all the syntax errors in a program
if they existed. A program written in C language has have been corrected
the extension .c (for example
first c) and after compilation the object program extension
. t will b•. obj (for example
C Library Functions
Executable Program
Linkür:
\.inker is a software tnat tianslate» object prcgran› ir.to a sirple
executable t›rugrari, as shown in Fig During this process. if i: cnuld nnt find the
definition of a paiti u:ai fun-tion that is used in the prog‹am, then it would assume
that it is öefined in Î!biary lt will raplace thi9 function in the object piogram with
the CcdC ffom C
!iUrury anô tnen cieate a single executable program
Loadet:
it s a software thai Iuads progfgfTl9 into memory and then executes tI›em
Debuggar:
it is a software that executes a program line by line. examiner the values
stureJ m yariaMes and helps Jn finding and remcving errors in progæms.
QS. List tbe uses of C language.
Ans: uses of C longuage:
C is a popu:ar and wideiy used programming language for creating coniputcr
prutJ‹u‹i›s A Ia•ge varmty of application programs and many modern operating
S}/SttîlTlS telU +vrIÎtBn l‹1 C
Q6. ExçdÆift fi lQ* 9 Uage cbaracter sel
Ans: C Language Charac1er Set:
"fhe C Language character set includes
Useofheaderftle!naCprogram
Q9. What is the structure of a C progmmf
Ans: Struca›re of a C Program:
The format according to which a program is written is called the structure of
program. The following is the structure of a C program.
Preprocessor direcfñ-es
Global dectarafioas
) ^°d: •* •••^O +U •« o•
L'ser-defined function
Fuarrio» 1 (optioo to use›-)
Fuacfioa 2
KEY POINTS
t Syntax refers to the rules of a programming language according to which
statements of a program are to be written
Semantic gives meaning to statements of a programming language.
Machine language is a programming language that is directly
understood by computer hardware It consists of zeroes and ones.
t Assamb§ language consists of symbolic codes or abbreviations. It was
developed to make computer programming easier than machine language. A
program called assembler is required to convert assembly language to
machine language for execution by the computer.
High level language is an English-oriented language. It is commonly used
for wnting computer programs A program called compiler/interpreter is
required to tfanslate htgh level language into machine language for
executo n by the computer.
Compiler is a computer program that translates a program written in a high
level language into machine language equivalent program . It converts the
entire program into machine language before execution by the computer
interpreter is a computer program that translates a program written in a
high level language into machine language It translates one instruction at a
time and executes it immediately before translating the next instruction
Programming environment is the set of processes and programming
tools used to develop computer programs
Integrated Development Environment (lDEj i= a comouter software tha!
is used to create, compile and run programs It bring9 all the processes ané
tools required for program dev•lopment into one place
Text ed"‹tor is a simple word-processor that is used to creat• and edit
source code of a program
Linker is a software that takes one or more object files, gene,rated by o
compiler and combines them into a single executable rogram.
Loader is a software that loads programs into memuy and then executes
them.
Debugger is a software that executes a program line by line. examines the
values stored in variables and helps in finding and removing errors in
S HORT QUESTIONS
q2. Give short answers to the following questions:
i. Define computer program.
Ans: ¢'omputer Program:
A computer program is a set of instructions (statements) written in a
programming language to solve a particular problem and achieving specific results
Any task performed by a computer is controlled by a set of instructions that are
executed by the micfoprocessor A large variety of programming languages have
been developed for writing computer programs to use the computer as a proLiem-
solving tool Each statement of a programming language has syntax and semai itic.
Dlfferentiate between syntax and semantîc.
Ans: t Syhtê^'
Syntax refers to the rules of a prngramming language according to which
statements of a program are to be written It describes the way to write correct
statements in a program Syntax of a programming language is similar to the
grammar of a natural language
For example, an assignment statement
consists of a ’zariahle and an
This is the syntax of
expression separated by equal sign as an assignment operator
assignment statement and it can be expressed as given beIOW
variable - expression.
4 Semantic: siatements of a proq amming language. It
Semantic gives meaning to n to be performed by a COf¥l uter when
describes the sequence of operatio s
executing the statements of a computer program.
For example, in the assignment statement.
sum = a + b; perform the expression , that is. add the
the semantic of the statement is to
values stored in variables a and b and store the result in variable
then
iil. Write three differences between assembly language and HLLs.
Ans: Differences {between high level and as9en'iMy langu6g9°
Features of high level language {HLLs):
i. High level languages are easily understandable.
ii. The programs that are developed in high level language are portable
iii. In cese of high level languages debugging of the coda is easy and the
program wntten is not machine dependent.
Features of Assembly language:
i. Although Assembly level languages are not easy to understand they are
relatively easier as compared to machine level languages.
ii. The programs written in this language are not portable and the
debugging process is also not very easy.
iii. The programs developed in assembly language are thoroughly machine
dependent.
iv. W"rce féur characteristics of HLLs.
Ans: Characteristics of High Level Languages:
Hiyh-level languages have the following characteristics.
1) These languages were developed to make computer programming simp!e,
easier and less prone to errors.
2) High level languages are not machine dependent. They enable programmers
to write programs that are independent of a particular type of computer
3) PfDgfams written in high-level languages must be translated into machine
language fry a cnmpiIe‹ or an interpreter before execution fry the computer
4) The process of finding and removing errors in programs (debugging) IS
easier in high-tevel languages compared to low level language.
s) High-level language programs are highly structured They allow
programmers to break lengthy programs into a number of modules which
can be written and tested independently. This makes writing and testing of
programs easier.
v, o«nn« I ntegrated Development Environment (IDE).
Ans: Integated Development Environment (IDE):
IDE is computer software that brings all the processes and tools required for
program development into one place. IDE’s aim is to make the iife of programmers
easier by grouping together all the tasks needed for building applications into one
environment
Today 's modern lDEs have user-friendly Graphical User lnterface (CUI)
Most of the new programming languages use Integrated Development Environment
tIDE) to craate. compile and run programe.
vi. Differenoatc between constant and variable.
Ans: ConctaetQ and Variables:
Constant and variables are used in expressions in computer programe. After
an expression is evaluated, the result of the expression is also stored in a variable.
4 59nstant:
Consta«ts are quantities whose values do not change during program
execution
Types of Connant:
They may be numenc. character or string.
i. Numeric Constants:
Numeric Constants are of two types, inteqer and floating-point numbers
Integer constants represent values that are counted, like the number of
students in a class Some examples of inteqer constants are 7145, -234, 26. etc.
Floating-point constants are used to represent values that-are measured,
like the height of a person which might have a value of 186.75 cm or the weight
such as 82.6 kilograms.
ii. Character Constant:
Character Constant is one of the symbols in C character set. It includes
digits 0 to 9, upper-case letters A to Z, lowei-case letters a to z, punctuation
symbols such as semicolon (;), comma (,), period (.) and special symbols such as +
-, =, >, etc A c,haracter constant is enclosed by single quotes such as ’a'.’s’. etc
iii. String Constant:
String Constant contains a string of characters within doubte quotes such as
“Hello Ahmed•. °a•, etc
R=---xc.Ëîords
] double . int I struct
break switch
e»«e } enum register \ typedef
gyt | extern reNrn I union
[unsigned
void
I •°i•tii•
@ whilo
do1 !*
ix. j/yhy comments ara * prog*nms*
lt ‹s a good programming practice to add comments in prograrn to make it
easy for others ta understand it. COfTlITiCft(ti B
the source oode are ignored by the
compiler.
Comments are udded in prrpraiiis when a tact s necessary to be
brought to the attention of program’s reader Generaily. programmers write
CGmmentu at the begir›ning of the program explair mg the reader what the program
is intended tu achieve and inside the program code where something is to be
clarified about tt e structure of the program
There are two types of comments.
4 Single line ‹x›mment
0 Multiple line comment
x. What is the uw of typecasting in C pograms3'
Ans: Typecasting in C Language:
Typecasting is a method to convert a •JariabIe from one data type to another
data tyye during program execution It makes a variable uf one type to act like
another typa.
For example, a variable of type int can act as a variable of type char
using typecasting This is required in some situations in programming in C language
For example, one use for typecasting is when there is need to /xoduce
ACSII characters for decimal cudes (0 to 127) To do this, the programmer will need
ie use to typecast to print out the integer variable as its charac1er equivalent usmg
fcnnat sp«cifar */ c.
The program that implements this is shown in Fig.
TypecastlnglnCprogram
There are two types o/ typecas¢fng In C
I Implicit typecasting
I Explicit typecasting
EXTENSIVE QUESTIONS
Q*• Ascribe tkefollowing HLLs.
a) C/C++ b) Visual Basic
c) CP d) Java
n^: Popular High Level Languages
(HLLs):
) C/C++:
C language was developed in early 1970s by Dennis Ritchie at Ball
L4boratones. C has become one of the most popular prcgrainming languages
t4day. It is a highly. struoures programming Iai›guage that is easy to understand and
use. In the pest, it was mainly used for writing system programs such as operating
systems, compilers, assemblers, etc
Today, it is used for writing all types of application prograrils as well, such as
wurd-processing programs, spreadsheet programs. database management
systems, educational prog•a * 8ames, etc.
C++ was developed by Bjarne Stroustrup also at Bell Laboratories during
1983-1985. C+• is a superset of C, meaning that any valid C program is also a valid
C++ program. The purpose of developing C++ was to provide programming facilities
tc easily and quickly write more powerful programs.
b) Visual Basic:
Visual Basic (VB) is a high level language which evolved from the earlier
version called BASIC. BASIC stands for Beginner’s All-purpose Symbolic Instruction
Code. VB is a very popular programming language for writing Windows and Web
applications. It provides a graphical development environment to programmers to
develop powerful Windows and Web applications
VB is commonly used for developing business programs such as payroll
system and inventory control program The user can also write programs related
with engineering, science. arts, education games, etc
¢1nc1uoc<scd1o.b>
Idtd
Typecasting in C program
There are two tyyes o{ typecuslitig in C
5 Implicit typecasting
¥ Explicit typecasting
Implicit Typecasting:
implicit typecasting is performed automatically by the compiler without
programmer s intervention. In thus type of casting the compiler converts all operands
into the data type of the largest operand Suppose an expression contains variables
of integer and double data types, the result will be evaluatéd to a double data type
For example in the program given below, compiler converts the sum of
two float numbers to an int.
#include <stdio.h>
void main(void)