Download - The Direct Data

greatgodlyElectronics - Devices

Nov 27, 2013 (3 years and 7 months ago)

121 views

1



Question Bank of CPU

SHORT QUESTIONS

Q. 1 Define Computer

Ans.

A computer is an electronic data processing
machine which accepts data from
the
outside world in the form of an input and manipulates, calculates, computes
on the
basic of a set of instructi
ons supplied and stored in the memory
and gives

the
required or desired result in the form of an output to the user. To put
in a simple
language, a computer is an information processing machine.


Q. 2 Define Hardware

Ans.
The physical parts of a compute
r are called the hardware. In other words, the


units that are visible and units which one can touch and feel are known as

the

computer hardware.


Q. 3


Define Software

Ans.

Software refers to the set of specific instructions that give directions to
a co
mputer

to perform certain specific or desired operations. In other words,
software

is
another component of a computer system which helps the user to

utilize

the

various

capabilities of a computer system for a specific purpose.


Q. 4
Define Firmware

Ans.



Firmware
often

refers to a sequence of instructions (software) that its




s
ubstituted

for hardware.


Q. 5
Define Analog Computer

Ans.

An analog computer is an electric system which recognizes data as
continuous

measurements
of physical quantities
,
such as pressure, voltage or temperature
along a continuous scale. The output of an analog computer will be usually in the
form of language readings or graphs.

Q. 6

Define Digital Computer

Ans.

A Digital computer is a combination of electronic devices,
designed to

manipulate
physical quantities of information that are represented in a digital

format. In other
words, a digital computer represents data in terms of discrete numbers and
processes data using the standard arithmetic operations.

Q. 7 What is a

hybrid computer ?

A
ns.


C
omputer which performs operations based on both analog and digital

principles in called as a hybrid computer. In other words, a computer system

that has
capabilities
,
behavior
, functions and principles of operation of both

anal
og and digital computer is called a hybrid computer.


2




Q. 8
Give full form of SSI, MSI, LSI, VLSI, ULSI.

Ans.
SSI
-

Small Scale integrated Circuits

MSI
-

Medium Scale Integrated Circuits

LSI
-

Large
Scale

integrated Circuits

VLSI
-

Very Large
Scale

Integrated Circuits

ULSI
-

Ultra Large
Scale

Integrated Circuits


Q. 9

What

is RAM ?

Ans.


Stand for random
-
access memory form of primary storage for holding


t
emporary

data and instruction volatile : Programs and data are eras
ed when

the power is

disrupted.

Q. 10

Explain ROM in brief

Ans.

Stands for read
-
only memory form of primary storage for holding permanent

data

and instructions permanent : program and data rename intact even when

power is

off other forms of ROM PROM
-

Programmable ROM EPROM


Erasable


PROM.

Q. 11 What is a Cache Memory ?

Ans.
Cache memory, also called in high
-
speed buffer, is a portion of primary


s
torage

used to speed the processing operations of the computer. Cache

memory

serves

as a working buffer

or temporary area to store both

instructions and data

that

must be accessed, often by the program being executed.

Q. 12

Define Bus.

Ans.



In microcomputers, the term bus
refers

to the paths between the components

of a


computer. There are two main

buses in a computer, the data bus and the

address


bus.


Q. 13
Define Data Bus

Ans.

The data bus is an electrical path that connects the CPU, memory, and the

other


hardware devices on the motherboard. Actually, the bus is group of
parallel

wires.

Q. 14 Define Address Bus

Ans.

The address bus is a set of wires similar to the data bus that connects the CPU

and


RAM and carries the memory addresses.

Q. 15

Define subroutines

Ans.

Subroutines are the smallest items of software normally pro
vided by a


manufacturer. These are usually routines devised to perform large numbers of

routine calculations e.g.,tax calculations

multiplications and division (if these

functions are not supported by hardware)

editing of data for input and output


Q. 16


Define Flowchart

Ans.


A flowchart is a graphical representation of a program flow or an algorithm

o
f

a


problem, to be solved by a computer. It is an aid to solve a complex
p
roblem


3




easily and efficiently.


Q. 17

Define Static Variables

Ans.

A static can only be accessed from the function in which it was declared, like


a
local variable. The static variable is not destroyed on exit from the function,


instead its value

is preserved, and becomes available again when the function

is

next called
.

Q.18

Define Token

Ans.

In a C source program, the basic element recognized by the compiler is the



"token". It is smallest part which does not break down further.

Q.19

What are identifiers ?

Ans.

"Identifiers" or "symbols" are the names you u
se for variables, types,


f
unctions



and labels in your program. Identifier names must differ in spelling

and case



from any keywords.


Q.20

Define Escape sequence

Ans.


Character combinations consisting of a
backslash (
\
) followed by a Setter or

b
y a



combination of digits are called "escape sequences
".

Q.21

Define Simple IF statement.

Ans.

The simplest form of the control statement is the If
statement
. It is very

f
requently

used in decision making and
allowing

the flow of program

execution
.

Q.22

Define If ELSE Statement.

Ans.

The if else is actually just on extension of the general format of if statement. If

the result of the condition is true, then program
statement 1 is

executed,



otherwise program statement 2 will be execute
d.


Q.23 Define nested IF ELSE.

Ans.

The if statement may itself contain another if statement is known as nested if



statement.


Q.24

What is a looping structure.

Ans.

When user (programmer) initialize, increment a counter variable and check





(test) it value at an appropriate place in th
e program by repeated task such


structure is known as looping structure.

Q.25 Define Entry Control loop.

Ans.


In this loop user first checks the condition & if the condition
b
ecomes true it



wi
ll

execute the body of loop.

Q.26 Define Exit Control loop

Ans.

In this loop first body of loop is executed then i
t

checks the condition
until

it
-
becomes true.

Q. 27 Define array

4



Ans. Array is a group of elements which have same data types. An

array is
a collection
of

variables of the same type.

Q. 28 Define String

Ans, String is a collection or group of character array.

Q. 29 What is gets
()

?

Ans.
g
ets
()

function is used to r
e
ad(get) a string into program.

Q. 30 What is puts
()

?

Ans.
p
uts
()

function is used to write(put) a string into program.

Q. 31 What is getcha
r
( ) ?

Ans.

getchar()

function is used to r
e
ad(get) a
ch
aracter
into program
.

Q. 32 What is putchar
( ) ?

Ans.
p
ut
char()

function is used to write(put) a
charact
er

into program.

Q. 33 What is strcat
(
) function used for ?

Ans. Strcat
(
) function is used to concatenate more than one string into'.single one
and
returns a single string from given input strings.

Q. 34 What is strcmpf ) function used for ?

Ans. strcm
p() function is used two compare between.two strings ad returns either T
or F
because of it compare the ASCII vajue of Two strings.

Q. 35 What is strlen( ) function used for ?

Ans. When user want to find the
length
of string
at that
time use strlen(
) function.

5



Question Bank of CPU

Q. 36 What is strcpy( ) function used for ?

Ans.

Strcpyf ) function assign one string value to other string va!ue in short it copy

the data from one string to another siring.


Q. 37 What is strrev
(

) function used for

?

Ans. Strrev()

function is used to print a string in reverse order.

Q. 38 Define recursion

Ans.

Recursion is the process where a functions is called itself but stack frame will

be
-
out of limit because function call will be infinite times. So a
termination

condition is mandatory to a recursion.


Q. 39 Define Pointer

Ans.

Pointer is nothing but a variable that contains the address of another variable

in
memory.

Q. 40 Define Structure

Ans.
A structure is a collection of variable under a si
ngle name. These variables canbe
of different types, and each has a name which is used to select it from the

structure. A structure is a convenient way of grouping^everal pieces of related

information together.


Q. 41 Define Clars


Ans.

Class is a us
er defined data type which has data and method both and it is

used to generate object from it.


Q. 42 Define Data Abstraction.

Ans.

Abstraction refers to give the general view. We are representing thing without

going into the background details. Class

contains the abstract data members

such as size, weight, height and function to operate on it.

Q. 43 Define Data Encapsulation.

Ans. Wrapping up

(pac.king) of data and functions into a single unit called class is

known as
T
he data encapsulation.

Q.
44 Define Data Hiding

Ans. Data members can't be accessed outside class in which it is declared. This

fundamental is known as the data hiding.

Q. 45 Define Inheritance

Ans.
Inheritance is the process by which object of one class acquire the prop
erties

and
method of another class. This is based on the hierarchical classification.

Inheritance provides the facility of reusability.

6



Q. 46 Define polymorphism

Ans.

Polymorphism is a Greek word and its meant is to take more than one form. An
operatio
ns show different behavior in different condition. The behaviour is used
on
the data type of variable and number of arguments. For example following
function calls are different in terms of number of arguments. sum(int a, int b, int
c)
sum(int.a, ind b) Th
e above fundamental is known as the Function Overloading.

Q. 47 Define Operator Overloading

Ans.

We can perform Operator Overloading is one in which operator is used for multiple
operations, for example '+' is a operator that is used for arithmetic opera
tion the same
operator we can use for the concatation of string and add two structure elements.

Q. 48 Define Dynamic Binding

Ans.

Binding means linking of two functions. There are two types of binding technique:
one is compile time binding in which linki
ng is performed during the time of
compilation. It is also known as early binding.

Q. 49 Define Late Binding

Ans.

Technique of binding is dynamic binding in which linking of function is performed
during the execution when function is called. It is also k
nown as the late binding.

Q. 50 Define Keywords

Ans.

In C++ program certain words have fixed mean for compiler and cannot be used
for
other purpose in program. These fixed words are known as keywords.

Q. 51 Define Polymorphism

Ans. The polymorphism

can be.defined as : "One Interface, multiple methods."

Q. 52 What is a virtual function ?

Ans.

Virtual function is example of runtime polymorphism. In virtual function we

have pointer of base class, which can point to either base class object or derive
class
object depending of address of object assigned to pointer variable.

When we use the same function name in both the base and derived
classes, the
function in base class is declared as virtual using the keyword
virtual before the
function declaration.

X X
X




7



FREQUENTLY ASKED QUESTIONS

1.

Define Computer

2.

State the difference between hardware & software.

3.

What is a firmware ?

4.

State the advantage of computer.

5.

Explain classification of computer.

6.

Write a shortnote on Hybrid Computer.

7.

Define
(1)

Mini Computer (2
) Micro Computer (3) Main Frame

(4) Super

Computer (5) Analog Computer (6) Digital Computer.

8.

Explain Basic structure of C.

9.

Explain the difference between RAM/ROM.

10.

What is Cache Memory ?

11.

Explain classification of memory with a neat diagram.

12.

State types of
ROM.

13.

What are the points be considered while buying a SMPS ?

14.

What do you mean by BUS. Explain different types of BUS.

15.

What are trigraph character ? How are they useful ?

16.

State all types of operators.

17.

Explain scope of variables.

18.

What is a token in C ?

19.

Expla
in Data Types in Detail.

20.

Disr . juish break &. continue.

21.

What is a looping structure ? Types of looping structure ?

22.

Differenciate while and Do while.

23.

What ia string ? Which are operations on string ?

24.

Explain (a) getcharf ) (b) putchar( ) (c) gets()

(d) puts( ).

25.

Explain string handling function.

8



Short Questions

26

What is a functions ?

27

Write a short note on call by value & call by reference.

28

What is recussion ? Explain it with example.

29

What is a pointer ?

30

Differenciate arrays fit pointe
rs.

31

What is a structure ?

32

Differenciate structure & arrays ?

33

What are the features of object oriented programming ?

34

What are benefits of OOPs ?

35

Explain structure of C++ program.

36

What is a token ?

37

Define Keyword.

38

Explain basic data t
ypes of C++.

39

What are user defined data types ? Explain with example.

40

What are derived datatypes ? Explain with example.

41

What are free store operators ?

42

Explain expression & their types.

43

Explain entry control loop & exit control loop.

44

Wha
t is prototyping ?

45

What are inline functions ?

46

Explain function overloading

47

How to make outside function inline ?

48

What is a friend function ? What are its special characteristics.

40

What is a virtual function ? Explain in detail

50

Explain Fla
sh Memory.

X X X






9



GTU
-
Dec.2008 Paper with Answers

Q. 1 Explain Basic
Structure of C Program

Ans.
A C Program may conain one or more sections shown in Figure

Documentation Section

Link Section


Definition Section

Global Declaration
Section

m
ain
(

) Function Section

Declaration Part

Executable Part

Subprogram Section

(User
-
defined functions)

The documentation section consists of a set of comment lines giving the name of the program,
the author and other details which the progr
ammer would like to use later, The link section
provides instructions to the compiler to link functions from the system library. The definition
section defines all symbolic constants.

There are some variables that are used in more than one function. Such v
ariables are called
global variables and are declared in the global declaration that is outside of al! the functions.

Every C program must have one main
(
) function section. This section contains two parts,
declaration part and executable part. The declarat
ion part declares all the variables used in the
executable part. There is at least one statement in the executable part. These two parts must
appear between the opening and the closing braces. The program execution begins at the
opening brace and ends at t
he closing brace. The closing brace of the main function section is
the logical end of the program. All statement in the declaration and executable part end with a
semicolon.


T
he subprogram section contains all the user
-
defined functions that are called i
n the main
function. User
-
defined functions are generally placed immediately after the main function,
although they may appear in any order.

All sections, except the main function section may be absent when they are not required.


10



Q. 2 Explain token in

C

Ans.

In a passage of text, individual words and punctuation marks are calk tofcens.1 Similarly, in a
C program the smallest individual units are known as C tokens. C has! six types of tokens as
shown in figure. C programs are written using these tokens

and! the syntax of the language


C TOKENS























Q. 3 Give a Switch case example.

Ans.
we write a menu driven program for simple calculator using switch.

#

include <stdio.h>

#

include <conio.h>

#

include <process.h>

Void main I)

I

int a
, b, c, choice;
clrscr();



printf("
\
n Enter the value of A");

scanf("%d",asa);

printf("
\
n Enter the value of B");

scanf("%d">&b);

printf("
\
n 1.Addition
\
n 2.subraction
\
n 3.Multipication 4.exit');

printf("
\
n Enter the choice");

scanf("%d" ,&choice);

Swit
ch (choice)

11



{

case 1:

c=a+b;


break;
case 1:

c=a
-
b;

break;

case 3:

c=a*b;

break;

case 4: exit(O);

default :

printf("
\
n Invalid choice");

break;


printf("
\
n Answer is C %d",c);
getch();

OUTPUT

Enter the value of A 12

Enter the value of B 13

1 .Add
ition 2. subtraction
3.multipication 4. exit

Enter your choice 1 Answer is
C 25

Q. 4
Explain Basic units of

C
omputer.

Ans.
As shown in Figure 2.1, a computer system consists of four parts :

Hardware, also known simply as the computer

Software,
also known as

P
rograms

Data, which the system converts into information

People, also known

as users

The term hardware refers to the part of the computer you can touch. It

consists of interconnected electronic devices that control everything the

compute
r does. When most people talk about a computer, they mean

hardware. The

term software refers to set of electronic instructions that tell the

hardware what to do. These set of instructions are also known as programs, and

each of them has a specific purpo
se. For example, you will probably use a word

processing program to enter, edit, and format text documents, such as letters,

memos, and reports, Word Perfect and Microsoft Word are two popular word

processing programs.


12



Data re
fers to the raw facts the computer can manipulate data can consist of

letters numbers, sounds, or images. However, no matter what kind of data is

entered into a. computer, the computer converts it into numbers. Consequently,

computerized data is digital
, meaning it has been reduced to digits, or numbers.

Within the computer, data is organized into files.

Computer file is simply a set of data or program instructions that has been given a name.
A file containing data is often called a document. .Although

many people think of documents
simply as text, a computer document can include many kinds of data. For example, a computer
document can be a text file (such as a letter), a group of numbers (such as a budget), or a video
clip (which includes images and so
unds). Programs are organized into files as well, but because
programs are not considered as data, these are not document files.

The last part of the computer system is the person who uses the computer. In discussion
about computers, people are u sally ref
erred to as users.


Q. 5 Explain Type conversions in detail.

Ans. C
permits mixing of constants and
variables

of different types in an expression, but
during evaluation it ad
d
res
s

to very strict
rules

of type conversion. We know that the
computer cons
iders one operator at a time, involving two operands.

If the operands are of
different types, the lower' type is automatically converted to the higher' type before the
operation proceeds. The result is of the higher type. A typical type conversion process
is
illustrated in Figure.



Fig. The Computer System

13

















Q. 6 Differentiate Break V/S Continue











Q.7
Explain goto

statement

14



Ans.
GOTO STATEMENT :



Definition : it is useful for unconditional transfer of control to the named label.



Syntax:

goto identifi
er ;

A statement label is meaningful only to a goto statement; in any other context, a
labeled statement is executed without regard to the label.

A jump
-
statement must reside in the same function and can appear before only
one statement in the same functio
n. The set of identifier names following a
goto has its own name space so the names do not interfere with other
identifiers. Labels cannot be redeclared.

It is good programming style to use the break, continue, and return statement in
preference to goto wh
enever possible. Since the break statement only exits from one
level of the loop, a goto may be necessary for exiting a loop from within a deeply
nested loop.


Q. 8

Difference between H/W and
S
/W



The main parts of a computer hardware are the storage dev
ices, the input devices, the
output devices and the Central Processing Unit (CPU).

Software

Software refers to the set of specific instructions that give directions to a computer to
perform certain specific or desired operations. In other words, a software

is another
component of a computer system which helps the user to
utilize

the various capabilities
of a computer system for a specific purpose. Some examples of the software are the
following.

15



>

Programming languages (BASIC, C, Pascal, C++, etc.)

>

Loader and

Linker

>

Editor

>

Compiler

>

Assembler

>

Operating systems

In general, software can be classified into two types: systems software and applications
software.

Q. 9 State and explain the Advantage of Computer

Ans.
The advantages of selecting and using comp
uters and how and why computers

have become an important tool in the modern world are summarized and given in follow
liv points.


1)

Speed

One the main reasons for using computers in the modern world is the speed. There is no
doubt that computers are
extr
emely

fast, accurate and can store a large amount of data
and can execute a long sequence of instructions automatically, h is only because of
computers that certain
activities

and operations can be accomplished in
today’s

world.

Some of the examples for su
ch activities are weather forecasting, control of industrial
operations, traffic and spacecraft control, reservations of tickets, etc. Without u;
-
computers, it is rather very difficult to take accurate decisions, predict the shortfall or]
excess of the pro
duction and carry out day
-
to
-
day managerial activities and functions)
associated with the social, financial, technological and other areas.

2)

Storage

Computer units can store and process vast amount of information in very lit
t
le

space. Also any informatio
n can be located, copied, deleted, browsed, navigated, modifier!

and displayed swiftly at the touch of a few keys. The above facility is unique to computer^

only.

3
)

Diligence and maintenance

Unlike human beings, computers do not get tired. They are only a

few mov
able

(mechanical)
parts and hence computers arc not susceptible to wear and tear and require frequent repairs. Hence it is
the best tool or machine for performing rep
ea
t
ed

jobs and operations without any actual limit.


4)

Accuracy

Computers are ma
ny times more accurate than human beings. Once progra
m
med long sequences
of operations can be performed without human
assistance

and the

necessary answers can be produced
and hence complex mathematical, scientific a engineering problems can be solved very
quickly and
accurately. A large amount of and information can be entered, stored and manipulated in computer
systems for tak
ing

logical decisions.

16



Q. 10 Explain Memory Classification with a neat diagram

Ans.


As mentioned earlier, memory can be classified

into two groups : prime (systecj or
main) memory and storage memory. The R/WM and ROM are examples of primJ memory; this is the
memory the microprocessor uses in executing and storing programs This memory should be able to
respond fast enough to keep up w
ith the execution speef of the microprocessor. Therefore, it should be
random access memory, meaning lha

the microprocessor should be able to access information from any register with the same speed
(independent of its place in the chip}. The size of a m
emory chip is specified in terms of bits. For
example, a 1 K memory chip means it can store 1 K (1022} bits {not bytes). On the other hand, memory
in a system such as a PC is specified in bytes. For example, 2M memory in a PC means it has 2
megabytes of me
mory. The other group is the storage memory, such as magnetic disks and tapes (see
Figure 2.16). This memory is used to store programs and results after the completion of program
execution. Information stored in these memories is nonvolatile, meaning infor
mation remains intact
even if the system is turned off. The microprocessor cannot directly execute or process programs stored
in these devices; programs need to be copied into theR/W prime memory first. Therefore, the size of the
prime memory, suchas512Kor

SM (megabytes), determines how large a program the system can
process. The size of the storage memory is unlimited; when one disk or tape is full, the next one can be
used.

Figure 2.6 shows two groups in storage memory: secondary storage and backup storag
e. The
secondary storage is similar to what you put on a shelf in your study, and the backup is similar to what
you store in your attic. The secondary' storage and the backup storage include devices such as disks,
magnetic tapes, magnetic bubble memory, an
d charged
-
coupled devices, as shown in Figure 2.16. The
primary features of these devices are high capacity, low cost, and slow access. A disk is similar to a
record; the access to the stored information in the disk is semi random. The remaining devices sh
own in
Figure 2.16 are serial, meaning if information is stored in the middle of the tape, it can be accessed after
running half the tape.













17



Figure 2.16

shown that the prime (system) memory is divided into two main groups Read/Write
memory (R/WM
) and Read
-
Only memory (ROM); each group includes several different
types of memory, as discussed below,

Q. 11 Short note on EPROM

Ans.

This memory stores a bit by charging the floating gate of an FET. Information is stored by
using an EPROM programmer,

which applies high voltages to charge the gale. All the
information can be erased by exposing the chip to ultraviolet light through its quartz
window, and the chipcan be re programmed. Because the chip can be reused many times,
this memory is ideally suit
ed for product development, experimental projects, and college
laboratories. The disadvantages of EPROM are (1) it must be taken out of j the circuit to
earse it, (2) the entire chip must be erased, and (3) the erasing process takes 15 to 20
minutes.

Q. 12

Short note on EE
-
PROM

Ans.

This memory is functionally similar to EPROM, except that information can be altered by
using electrical signals at the register level rather than erasing all the information. This has
an advantage in field and remote control

applications. In' microprocessor systems, software
update is common occurrence. If EE
-
PROMs are used in the systems, they can be updated
from a central computer by using a remote link via telephone lines. Similarly, in a process
control where timing infor
mation needs to be changed, it can be changed by sending
electrical signals from a central place. This memory also includes a Chip Erase mode,
whereby the entire chip can be erased in 10 ms vs. 15 to 20 min. to erase an EPROM.
However, this memory is expen
sive compared) to EPORM or flash memory (described in
the next paragraph).

Q. 13 Explain Flash Memory

Ans. This is a variation of EE
-
PROM that is becoming popular. The major difference i between
the flash memory and EE
-
PROM is in the erasure procedure:

the EE
-
PROM: can be erased
at register level, but the flash memory must be erased either in its entirety or at the sector
(block) level. These memory chips can be erased and programmed at least a million times.
The power supply requirement for programming

these chips was] around 12 v, but now
chips are available that can be programmed using a power supply as low as 1.8 V.
Therefore, this memory is ideally suited for Jow
-
power systems.

In a micro processor
-
based product, programs are generally written in RO
M, and data that
are likely to vary are stored in R/WM. For example, in a microprocessor
-
controlled

18



Question Bank of CPU

19



oven, programs that run the oven are permanently stored in ROM, and data such
as
baking period, starting time, and temperature

are entered in R/W memory
through the
keyboard. On the other hand, when microcomputers are used for
developing software
or for learning purpose, programs are first written in R/W
memory, and then stored on
a storage memory such as a cassette tape or flopp
y
disk.

Q. 14 Explain CRT

Ans.

The monochromatic CRTs used for graphics displays are essentially the
same as those used in biack and white home television sets
-

Figure 3.31
illustrates the basic operation of a CRT.










A beam of electrons (cathode
rays) emitted by an electron gun, passes through
focussing
and deflection systems that direct the beam towards specific positions
on the phosphor
coated screen. The screen phosphor coating is organised into a grid
of dots called pixels
(picture elements).
The phosphor then emits a small spot of
light at each position
contacted by the electron beam. Beacuse the light emitted by
the phosphor feeds very
rapidly some method is needed for maintaining the
screen picture.

One way to keep the phosphor glowing is to

redraw the picture repeatedly by
quickly directing the electron beam back over the same points. This type of display
is called a
refresh CRT.
Refresh rate is typically 60 per second for raster displays.

As refresh rate decreases, flickers develop because
the eye can no longer integrate
the
individual light impulses coming from a pixel. The
refresh rate above which the
picture
stops flickering and fuses into steady state is called Critical Fusion
Frequency.

19



20

Long Questions

Q. 15
W
hat

is a Static
vari
able?

Ans.

Another class of local variable is the static type. A static can only be accessed
from the function in which it was declared, like a local variable. The static
variable is not destroyed on exit from the
function;

instead its value is preserved,
and becomes available again when the function is next called. Static variables are
declared as local variables, but the declaration is
preceded

by the word static.

Q. 16 Explain scope of Variable in C

Ans.

The scope of variable determines over what part
s of the program a variable is
actually available for use. Lifetime refers to the period during which a variable
retains a given value during execution of a program.


Example of Local and global va
riables :


int b =99;

main
(
)

{

i
nt a =10;

printf
(“
'a
=
%d b=%
d",a,b
)
;

f1();


}

void f1()

{

i
nt a= 100;

printf
(“
'a
=
%d b=%d",a,b
)
;

getch
(
);

}

OUTPUT

a=10 b=99
a=100


b=99

Description :

here in main the scope of variable a is logical to function main(),then
when we move to function fl(),the scope of variable a is
ended and new value of a is set
to 100.

20




Storage class


Visibility


Lifetime


Auto


Only in that function


Until the end of that



or block where it is


function or block.



declared





Static


Only in that function


Global


None


Entire file


Enti
re program


(global variable)




Q. 17 Explain Data types in C

Ans.

A C language programmer has to tell the system before
-
hand, the type of numbers or
characters he is using in his program. These are data types.

Primary Data types :

All C Compilers ac
cept the following fundamental data types or primary datatypes


Sr

N
o


Name

Declaration Name

I.

Integer

i
nt

2.

Character

char

3.

Floating Point

float

4.

Double precision floating point

double

5.

Void

void

Integer Data type :

Integers

are whole numbers with a machine dependent range of values, A good programming
language as to support the programmer by giving a control on a range of numbers and storage
space. C has 3 classes of integer storage namely short int, int and long int. Alt of

these data
types have signed and unsigned forms. A short int requires half the space than normal integer
values. Unsigned numbers are always positive and consume all the bits for the magnitude of
the number. The long and unsigned integers are used to decl
are a longer range of values.

21



Float Data type :

Floating point number represents a real number with 6 digits precision. Floating point
numbers are denoted by the keyword float. When the accuracy of the floating point
number is insufficient, we can use th
e double to define the number. The double is same
as float but with longer precision. To extend the precision further we can use long I

double which consumes 80 bits of memory space.

Character Data Type :

A single character can be defined as a defined as a

character type of data. Characters]

are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be

explicitly applied to char. While unsigned characters have values between 0 and 255,

signed characters have values from
-
128 to 1
27.

Void Data Type :

Using void data type, we can specify the type of a function. It is a good practice to avoid]

functions that does not return any values to the calling function

Range and keyword of Data Type

User defined type declaration. Declaration
of Storage Class, auto, static, extern, registerJ

Denning Symbolic Constants, Declaring Variable as Constant and Volatile Variable



















22





















User
-

Defined Data Type

In C language a user can define an identifier that represen
ts an existing data type. The user
defined data type identifier can later be used to declare variables.

Q. 18 Explain simple IF

Ans.

Definition:

The simplest form of the control statement is the If statement. It is very
frequently used in decision makin
g and allowing the flow of program execution.

The If structure has the following syntax


If (Condition)

statement;


Description:
The statement is any valid C' language statement and the condition
is any valid C' language expression, frequently logical ope
rators are used in the
condition statement. The condition part should not end with a semicolon, since
the condition and statement should be put together as a single statement. The
command says if the condition is true then perform the following statement o
r If
the condition is fake the computer skips the statement and moves on to the next
instruction in the program.

Example : Program for even number.

Ans :


# include <stdio.h> //Include the stdio.h file


void main (
)

// start of the program


{

int numbers;

// declare the variables

23




printf ("Enter A Number: :"); / / message to the user


scanf ("%d", &number);

// read the number from standard input


if (number %2== 0)

// check whether the number is a negative number


printf ("The Enter Number is EVEN %d

\
n", number);

// print the value


}

OUTPUT

Enter A
Number:

12

The Number is Even 12

Q. 19 Explain IF
-
ELSE statement

Ans.

Definition:

if else is actually just on extension of the general format of if
statement. If the result of the condition is true,
then program statement 1 is
executed, otherwise program statement 2 win be executed. If any case either
program statement 1 is executed or program statement 2 is executed but not both
when writing programs this else statement is so frequently required that

almost all
programming languages provide a special construct to handle this situation.
Syntax:

If
(Condition)

{


True

Block;

}

Else

{


False

Block

}

Example : Program for even number and Odd Number.

Ans :


# include <stdio.h> //Include the stdio.h file


void main () // start of the program


{


int numbers; // declare the variables


printf ("Enter A Number: :"); // message to the user


scanf ("%d", &number); // read the number from standard input


if (number %2=

= 0)

// check whether the number is
a negative number


{



printf ("The Enter Number is EVEN %d
\
n", number);

/ / print the True block value


}


else

{
24




printf ("The Enter Number is ODD %d
\
n", number);

/ / print the false block value
H
-

}

OUTPUT

Enter A Number : 12

The Numbe
r is Even 12

Enter A Number : 13

The Number is Odd 12

Q. 20 Explain IF
-
ELSE ladder

Ans.

The elseif ladder statement is used to carry out a logical test and then take one of
many possible actions depending on the evaluation of the condition(i.e wheth
er the
outcome is true or false. Syntax : The syntax for else if ladder as under :

If (expression)

Statement;
else if (expression)

Statement;
else if (expression)

Statement;
else if

(
expression)

Statement;

else

Statement;
Description:

(1)

The expression must b
e placed in parenthesis as shown

(2)

In this form, the statement will be executed only if the expression has true

value.

(3)

If the expression has a false then tbc control will be transferred to next condition

and so on.

(4)

If all the conditions are evaluated false t
hen else block will be executed.

25



Q. 21 Explain Switch Statement

Ans. Definition:
some times in C Program we face more than one alternative choices
for different operations. So the program becomes difficult
for
reading and
executing. For this occur
rence c provide the multi way decision statement
known as
switch. The switch statement check(test) the value of a given choice
variable or expression against a list of case values and when it match a logical
block which
associated
with that
case
is execu
ted.
Syntax :
switch (variable
or expression)

case value
-
1:

Block
-
1
break;

case
value
-
2:

Block
2
break;

default:

default block
break;

Statement x;

Syntax
Description ;

(1)

The expression or variable is either integer
or character
value,

(2)

Value
-
1 ,value
-
2 a
re called as case
labels.

(3)

Each of this label value is unique in switch.

(4)

block
-
I, block
-
II are statement (logic
of the
block)
contain 0 or
more

statements.

(5)

Case is always ended with . ( Colon)

(6)

When the switch statement is executed then the value of the va
riable or

expression compares with block of statements and if it found it executes

the block of the statement.

(7)

break statement at the

end of each block which represent end of a

particular block.

(8| When value is not with any block of the switch c
ase it will execute the
default statement. Default is an optional case.

26



Q. 22 Explain GOTO Statement
,
GOTO STATEMENT :



Definition
: it is useful for unconditional transfer of control to the named label.



Syntax :

goto identifier ;

A statement label

is meaningful only to a
goto
statement; in any other context, a labeled
statement is executed without regard to the label.

A
jujnp
-
stqtement
must reside in the
same
function and
can appear before
only one
statement in the same function. The set of
identif
ier
names following
a goto
has its own
name space so the names do not interfere "with other identifiers. Labels cannot be
redeclared.

It is good progr a mining style to use the
break, continue, and return
statement in
preference to
goto
whenever possible.
Since the
break
statement only exits from one
level
of the loop, a
goto
may be necessary for exiting a loop from within a deeply nested
loop.

Q. 23 Explain Entry Control LOOP

Ans.


Definition
:
when user (programmer) initialize .increment a counter
varia
ble
and check (test) it value at an appropriate place in the program by
repeated task such
structure is known as looping structure. The general syntax
of
while loop
as under:

Syntax :

while ( test
-

condition)

(
Body Of The Loop

!

Statement X;

Syntax Descri
ption :

(1)

It is known as "Entry Control Loop".

(2)

In this loop first user can check the condition and if the condition become true

it will execute the body of the loop.

(3)

If condition becomes false control goes to statement X.

(4)

In this loop condition is checkjtes
t) until it becomes false.

27





Q. 24 Explain Exit Control Loop

Ans.


Definition

: when user(programmer) initialize ,increment a counter variable
and check (test) it
value

at an appropriate place in the program by repeated
task such structure is known as

looping structure. The general syntax of
do
while

loop as under:

Syntax :
do


{

Body Of The Loop

} while (test
-

condition);
Statement X;

Syntax Description:

(1)

It is known as "Exit Control Loop".

(2)

In this loop first body of the loop is executed then after ch
eck the condition until

the condition become true.

(3)

If condition becomes false control goes to statement X.

(4)

In this loop condition is check(test) at last

Q. 25 Explain String Handling Function.
Ans. STRING HANDLING FUNCTIONS

Whenever user want to per
form different string manipulation operations "C" provides
the way to perform the different String Handling functions :

1.

s
trcat
()

2.

s
trcmp
()

3.

strlen
()

4.

strcpy
()

5.

strr
e
v
()

strcat : String Concatenate Function

s
trcat function is used to concatenate more than one
string into
single one
and returns
a single string from given input strings.

28



Question Bank of CPU

29



Q. 26
Differentiate

While V/
S

Do While
Ans.

while

do while

it is called as entry control loop

because of Condition is tested at

the entry
time

It is called as entry control loop

because of Condition is tested at exit

time.

Loop even may not be executed

a single rime

Loop always at least executed for

one time.

Example

i
nt a = 1

while(a<5)

{

printf("
\
n a
=%d",a);

a++;

}

p
rint
f
(“
\
nbye

)
;

OUTP
UT

1

2

3
4 5

bye

Example

i
nt a =
10

do

{

printf(“
a=%d"
,
a);

a++;

}
while(a<10
);

p
rint
f(“
\
nbye”)
;

OUTPUT

10

bye


29



Q. 27 Explain Call by Value
&
Call by Reference

Ans.

In call by value, the actual parameter "n" is independent of the formal parameter
"x".
W
hen a function (such as "chang
e
it
()
") is called, the

value of "n" is determined and

is
stored
in "x". Any subsequent changes to "x" do not affect "n".

Ca
ll
-
by
-
value

evaluation is the most common evaluation strategy, used in
languages as far
-
ranging as C an
d Scheme. In call
-
by
-
value, the argument expression
is
evaluated, and the resulting value is bound to the corresponding variable in the
function (usually by capture
-
avoiding substitution or by copying the value into a new
memory region). If the function or

procedure is able to assign values to its parameters,
only the local copy is assigned


that is, anything passed into a function call is unchanged
in
the caller's scope when the function
returns
.

Ca
l
l
-
by
-
value is not a single evaluation strategy, but rath
er the family of evaluation strategies


in which a function's argument is evaluated before being passed to








the function. While many programming languages (such as Kiffel and Java) that use call
-
by
-
value evaluate function arguments left
-
to
-
right, som
e evaluate functions and their arguments
right
-
to
-
left, and others (such as Scheme, OCaml and C) leave the order unspecified (though
they generally guarantee sequential consistency

The arguments passed to function can be of two types namely

1.

Values passed

2.

A
ddress passed

The first type refers to call by value and the second type refers to cal! by reference.

Example :
-
1

main()

!

int x=50, y=70;
interchange(x.y);
printfTx=%d y=%d",x,y);

interchange(xl.yl)

int x 1 ,y 1;

j

int zl;
zl=xl;

30



xl=yl;

yl=zl;

printf("xl
=%d yl=%d",xl,yl);

!

Here the value to function interchange is passed by value.

Example
-

H

main()

i
i

int x=50, y=70;
interchange(&x,&y);
printf("x=%d y=%d",x,y);

interchange

(x 1 ,y 1)
int*xl,*yl;

{

int z
\
;

zl=*xl;

*xl=*yl;

*yl=zl;

printf("*x=%d ^y=%d',


Here the function is called by reference. In other words address is passed by using

symbol & and the value is accessed by using symbol *.

The main difference between them can
-
be seen by analyzing the output of Example
-

I

and Example
-

II.

The output of
Example
-
I that is call by value is

xl=70yl=50

x=50 y=70
But the output of Example
-
II that is call
by reference is

*x=70 *y
-
50

x=70 y=50

Q. 28 What is Recursion ? Explain with example.

Ans.

Recursion is the process where a function is called itself but
stack frame will be
out of
limit because function cali will be infinite times. So a termination condition is
mandatory to a recursion.

In C, Recursion can be divided into two types:

(a)

Run
-

Time Recursion: Normal as in C

31



(b)

Compile
-

Time Recursion: By using Temp
late

recursion a function call itself in a simple manner and by termination condition it

terminates.
This process called 'Winding' and when it returns to caller that is called tin
-
Winding'.
Termination condition also known as Base condition,
-
.mple: Factor
ial calculation by linear
recursion

Run
-
Time Version
int Fact(long n)

32



32

Long Questions



if(0>n)
return
-
1;
if(0 == n)
return
1;
else

!

return ( n* Fact(n
-
l));

Winding Process:

Function called Function return

Fact(6) 6*Fact(5)

Fact(5) 5*Fact(4)

Fact(4
)

4*Fact(3)

Pact(3)

3* Fact(2)

Fact(2)

2* Fact(l)

Fact(l)

1* Fact(O)

Terminating Point

Fact(O)

1

Unwinding Process

Fact(l)
Fact(2)
Fact(3) Fact(4) Fact(5)
Fact(6)


Q. 29 Explain of
C++ Program

Ans.
STRUCTURE OF
C++
PROGRAM







Include Statements











Class Declaration











Class function definition











Main program










Fig. Structure of C++ program

In C++ program first we are writing include preprocessor statements to include various
header (library) file. After incl
ude statement there is class declaration. In class declaration
we are defining class, its member variable and declaration for the member function.
After class declaration there is class member function definition in which we are writing
33



the definition of v
arious class member function. At last there is main program, which
start the execution of program and create the object of class. The general structure of
C++ program can be shown in Fig.3.

Generally in C++ program class declaration, class member function
definition and main

program is written in three separate files.

Class declaration file and class member.

function definition file is included into the

main program to link all of them. This

structure is known as the
client
-
server

architecture.

In client
-
s
erver architecture

we have client requests for service to server

and server provides service to client. One

client can get service from more than one

server and similarly one server can

provides the service to multiple clients.

Same fundamental is used a
t here. Class

is act as server and program acts as client.

Main program (Client) can use more than


one class (berver) similarly one class

(server) can be used for more than one program (client).

34



34

Long Questions



Q. 30 Explain types of Primary Da
ta Type.

Ans. In C++ language primary data types are mainly four: int (Integer value), float
(single precision value), double {double precision value), char (Character value). There
are also some other data types but it is combination of all these four dat
a types such as
long int, long float, unsigned int, etc.







Integers are whole numbers. Integer data type variable can be declared as

int variablename

In 16
-
bit machine the size of integer type variable is 2 bytes that means it can store
the va
lue from
-
2
LS

to (2'
5
)
-
l i.e. from
-
32,768 to +32,767. In 32
-
bit machine the size of
integer type variable is 4 bytes that means it can store the value from
-
2
31

to (2
31
)
-
1 i.e.
from
-
2,14,74,83,648 to +2,14,74,83,647. Integer data type also can be divided
into
different sub type.

a.

Signed Integer :

Signed integer is a number, which contains either positive or negative sign.

Signed integer variable can be declared using

signed

int uariablename

By default integer is signed type of variable.

b.

Unsigne
d Integer :

The unsigned integer has not posses the size so you cannot represent sign with
this number. But it provides the facility to store higher value using same number
of bytes. In 16
-
bit machine the size of unsigned integer is 2 bytes but it can
stor
e the value from 0 to 65,535.

unsigned

int variablename

35



Question Bank of CPU

35

c.

Long Integer :

If you have to store higher value than the given range then there is use of long
integer. In Jong integer for 16
-
bit machine there is use of 4 bytes
so we can
represent the value from
-
2,14,74,83,648 to +2,14,74,83,647.

long

int

uariablename

Unsigned long integer can represent the value from 0 to
4,294,967,295.

unsigned

long
,
int

uariablename

d.

Short Integer :

It occupies only 2 byte In 16
-
bit mac
hine. That means your can represent the

number from
-
32,768 to 32,767.

short int uariablename
Float Data type
-

Float variable can contain any rea! number. It represents the value with single precision.
In 16
-
bit machine the size of float variab
le is 4 bytes. We can represent the value from
3.4E
-
38 to 3.4E+38 by using float variable. Float variable cannot be have any signed or
unsigned characteristic. We cannot use signed and unsigned format for the float variable.
Double Data type
;

Double data
type is used to declare the variable for any real number but it represents
the value with double precision. In 16
-
bit machine the size of double variable is 8 bytes.
We can represent the value from 1.7E
-
308 to 1.7E+308 h
\

using the double data type.
There
is also another data type long doubic in which 10 bytes are required in memory.
The range for the long double variable is 3.4E
-
4932 to 1.1E+4932 We cannot use
signed and unsigned format for the float variable.
Character Data type :

A single character can b
e defined as a character (char) data type. The size of the variable
declared as char is 1 byte. We can use two kind of character variable :

a.

Signed character :

Whenever you not specify any qualifier by default character variable is signed
character. We c
an represent the value from
-
128 to +127 by using singed character

b.

Unsigned character:

Whenever you declare the character as the unsigned character type you can

represent the value form 0 to 255

We can also represent the
*void'
as the primary data type.

Variable of type Void' doesn't
hold any value but it is mainly used for the return value and in pointer.
In C void is
not a primary data type.

36



Long Questions

Q. 31 Explain Virtual Functions

Ans. Virtual function is example of runtime polymorphism. In v
irtual function we
have pointer of base class, which can point to either base class obje
-
n or derive class
object depending of address oi object assigned to painter variable.

When we use the same function name in both the base and derived classes, the
func
tion in base class is declared as
urrtual
using the keyword
virtual
before the
function declaration.
class Base

!
public :

void baseGwnf ) [

cout « "It is base class own Function
\
n";

void sirnFun( ) ]

cout « "It is simple function in base class
\
n
B
;

virtu
al void virFun( } j

cout « "It is virtual function is base class
\
n;

class Derive : public Base J
public :

void deriveOwn( ) |

cout « "H is derive class own function
\
n°;

}

void simFunt ) ]

cout « "It is simple function in derive ctass
\
n";

void
virFunf ) {

.
cout « "It is version of virtual function ir
derive class
\
n";

i

37




37

void main( ) {
Base *p;
Base b;
Derive d;

p = &b;

//
Pointer points
to base
class

p
-
;> baseOwnf ); //
Call from base class

p
-
? simFunl I; //
Call from base class

p
•>
virFun(

);

//
Call from 'base class

p = otd;

//
Pointer points to derive class

p
-
> deriveOwn(); //
Cannot call. Give

// compilation error.
p
-
> simFunf ); //
Call from base class

// because it
is
not inrtual

p
-
> virFun( };

//
Call from derive class

i
j

Rules
for Virtual function :

1.
The
virtual function must be member of some class. 2
It cannot be static function.

3.

It can only accessed by pointer variable but not by simple object

variable.

4.

It can be a friend of another class.

5
It must be de
fined in base class although it is not used in base class.
It is not necessary to define the virtual function in derive class.

6.

Virtual function defined in base class and derive class have same

number of arguments, same type of argument, and same return typ
e

otherwise it is considered as function overloading by compiler.

7.

We cannot have virtual constructor but we have virtual destructor.

8.

Pointe of base class can point to object of derive class but vice
-
a
-
versa

is not true.

Q. 32 List
all Operator In C and exp
lain them.

Ans. Operators are used with operands to build expressions. An
operator
computes
new values out of old ones. An
expression
consists of variables, constants, and
operators combined to perform some useful computation. For example the following
is
an expression containing two operands and one operator.

38



38

Long Questions



c = a + b

The following list of operators is probably not complete but does highlight the common
operators and a few of the outrageous ones....

(1)

Arithmetic Operator

(2)

Relationa
l Operator

(3)

Logical Operator

(4)

Assignment Operator

(5)

Conditional Operator or Ternary Operator

(6)

Increment(++)
-

Or
-
Decrement Operator(

)

(7)

Size of Operator

(8)

Comma Operator

(9)

Bitwise Operator

ARITHMETIC
OPERATOR :

The basic operators for performing arithmetic are the
same in many computer languages:










The
-

operator can be used in two ways: to subtract two numbers (as in a
-

b), or to negate
one number (as in
-
a + b or a t
-
b).

When applied to integers, the division operator / discards any remainder, so 1 / 2 i
s 0 and
7 / 4 is 1. But when either operand is a floating
-
point quantity (type float or double), the
division operator yields a floating
-
point result, with a potentially nonzero fractional part.
So 1 / 2.0 is 0.5, and 7.0 / 4.0 is 1.75. The modulus operato
r % gives you the remainder
when two integers are divided.

1 % 2 is I; 7 % 4 is 3. (The modulus operator can only be applied to integers.)

§ An additional arithmetic operation you might be wondering about is

exponentiation. Some languages have an exponenti
ation operator (typically ' or **), but C
doesn't. (To square or cube a number, just multiply it by itself.) Multiplication, division,
and modulus all have higher precedence than addition






39



and subtraction. The term "precedence" refers to how "tightly"

operators bind
to their
operands (that is, to the things they operate on). In mathematics,
multiplication has
higher precedence than addition, so 1 + 2 * 3 is 7, not 9. In other words, 1 + 2 * 3 is
equivalent to 1 + (2 * 3). C is the same way.
All of thes
e operators "group" from left to
right, which means that when two or
more of them have the same precedence and
participate next to each other in an expression, the evaluation conceptually proceeds
from left to right. For
example, 1
-

2
-

3 is equivalent to

(I
-

2)
-

3 and gives
-
4, not +2.
("Grouping" is
sometimes called
associativity,
although the term is used somewhat
differently
in programming than it is in mathematics. Not all C operators group from left
to
right; a few group from right to left.)

Whenev
er the default precedence or associativity doesn't give you the grouping
you want,
you can always use explicit parentheses. For example, if you wanted
to add 1 to 2 and
then multiply the result by 3, you could write (1 + 2) * 3.

Q. 33 What are the Limita
tion of Computer ?

Ans. With the formation of powerful features of a computer, it may seem that the
solution to any problem in this world is possible with the help of computers, but
it
is not so. Although computers possess several superhuman advantages, th
ey
do
not have the thinking capacity or the cornmonsense. They do not understand
anything and so they do not have brains. This is becuase computer is merely a
combination of electronic circuits in which bits of information and data travel
with lightning sp
eed. In other words, computers lack the intelligence and common
sense of human beings. It does not have the sense of feel, touch, smell, sight and
hearing. One can sum up the following as the limitations of a computer.



Computers cannot operate or function

by itself without the assistance

of human beings.



It cannot identify any problem of the world on tts own that requires a

solution.



It cannot identify the input/output needed to solve a problem.



It cannot identify and collect the data needed to produce any

desired

output.



It cannot desi gn or devel op it s own soft ware t hat i s necessary to

transform any data into a desired output.



Computers cannot interpret and use information that is stored in a

computer.

X X X

40



1*1
2*1
3*2*1 4*3*2*1

5*4*3*2*1 6*5*4*3*2*1

41



42



Continue Statement:

The continue statement skips the remaining statements in the body of the loop, and
continues with the next iteration of the loop.

Example:

Write your own program that reads integers given by keyboard and

applies
following rule above
them: if the given number is smaller than zero, program should print
error message and stop reading numbers. If the given number is bigger than 100, it should be
skipped and program should rfad another number. All other numbers should be red and
printed. P
rogram must stop reading numbers when 0 or error shows up.

ffinclude <stdio.h>

void main() {
int x;
do{

printf ("Input number :
\
n"];
scanf(
a
%d", &x );
if (x < 0) {

printf("Not allowed value
\
n");
break;

/* escapes the loop */
1

I

if (x > 100) i

print!("Skip
ping the value
\
n");
continue; /* jumps to second
iteration */

printf ("Given number is : %d", x);
while (x != 0);

43



iii).Explain
Following String Manipulation Functions.

05

Strcmp(),strlen(),strcat(),strstr(J,strchr().

ANS:

I

Strcmp():

Syntax:

^include <str
ing.h>

int strcmp' const char *strl, const char *str2 );
Description:

The function strcmpQ compares strl and str2, then returns:

Return value

Explanation

less than 0

strl is less than str2

equal to 0*

s*rl is equal to str2

greater than 0 strl is gre
ater than str2

strlenf)

Syntax:

strlen( char *str );

Description:

The strlenQ function returns the length of str (determined by the number of

characters before null termination).

strcat():

Syntax:

char *strcat( char
*strl, const
char *str2 };

Description:

The strcatQ function concatenates str2 onto the end of strl, and returns strl,
strstr():
Syntax:

char *strstr( const char *strl, const char *str2 );
Description:


44



The function strstrO returns a pointer to the first occurrence of str2 in strl, or NULL
if
no match is found.

strchr():

Syntax
-
char *strchr( const char
*str, int ch );
Description:

The function strchrQ returns a pointer to the first occurence of ch in str, or NULL
if ch is not found.

OR

Q
-
3 Do as Direct

i)

Draw
Flow chart to do
the sum of
10

ele
ments read from user.







05

45




ii)

List out Operators used in C Language and

explain any Four with Example

05

Ans:

1)

Arithmetic operator

2)

Logica
1

operator

3} Assignment operator

4)

Relational operator

5)

Conditional operator

6)

Bit
-
wise operator

7] Special ope
rator

Ex planations:
Arithmetic
Operator

+

Addition

Subtraction

/

Division

*

Multiplication

%

modulo

Decrement (post and pre)

++

Increment (post and pre)

Arithmetic cperator are used for arithmetic operation.

Assignment

These all perform an arithmetic oper
ation on the lvalue and assign the result
to the

lvalue.

Here is the full set.

*= Multiply
/=
Divide.
%=
Modulus.
+=
add.

Subtract.
«=
left shift. »=
Right shift.
&=
Bitwise AND.

bitwise exclusive
OR (XOR).
1=

bitwise inclusive OR.

46



104

____________________________

GTU Dec. OS Paper with Answer

Logical/Relational

== Equal to
!=
Not equal to

>
<
>=

Logical AND
| | Logical OR
! Logical KOT
These
operators are used for Logical and Relational operation.

Bitwise

&

AND (Binary operator)
| inclusive OR exclusive
OR
« shift left.

» shift ri^ht.

one's complement
These operators are
used for Bitwise operation

III).
what do you mean by constant in C language?

Explain types of constants in d
etail.

04

Ans:

Constants

A constant value is the one which does not change during the execution of a
program. C supports several types of constants.

1.

Integer Constants

2.

Real Constants

3.

Single Character Constants

4.

String Constants

47



Question Bank of
CPU

105

Inte
ger Constants An integer constant is a sequence of digits. There are 3 types of
integers namely decimal integer, octal integers and hexadecimal integer.

Integers
consists of a set of digits 0 to 9 preceded by an optional + or
-

sign.
Spaces, commas and non

digit characters are not permitted between digits. Example
for valid decimal integer constants are

123
-
3100

Octal
Integers
constant consists of any combination of digits from 0 through 7 with a
0 at the beginning. Some examples of octal integers are

O26

O

O676

Hexadecimal integer
constant is preceded by OX or Ox, they may contain alphabets
from A to F or a to f The alphabets A to F refers to 10 to 15 in decimal digits. Example
of valid hexadecimal integers are

0X2

f

.

OX8C

Single Character Constants

A Sin
gle Character constant represent a single character which is enclosed in a pair
of quotation symbols.

Example for character constants are
'5'

All character constants have an equivalent integer value which are called ASCII
Values.

String Constants

48



106

GTU

Dec. OS Paper with Answer



A string constant is a set of characters enclosed in double quotation marks. The
characters in a string constant sequence may be a alphabet, number, special character
and blank space. Example of string constants are
"1234"
'G
od Bless"

Backslash Character Constants [Escape Sequences]

Backslash charactei constants are special characters used in output functions. Although
they contain two characters they represent only one character. Given below is the,
table of escape sequence a
nd their meanings.


Constant


Meaning


*
\
«'


.Audible Alert (Bell)


'
\
v


. Backspace


'
\
F


. Formfeed


'
\
n'


.New Line


V


.Carriage Return


'
\
t'


.Horizontal tab


'
\
v


.Vertical Tab


V


.Single Quote


t
\

»r


.Double Quote


'
\
?'


.Question Mark


'
\
V


.Back Slash


'
\
0'


.Null


49



Question Bank of CPU

] 07

Q
-
4) Do as directed

i) What is Pointer? Write a program to do swapping

of two elements using pointers.

05

Ans:

In c a pointer is a variable that points to or references a memory location in

which data
is stored. Each memory cell in the computer has an address that can be used to access
that location so a pointer variable points to a memory location we can access and
change the contents of this memory location via the pointer.

Pointer declara
tion:

A pointer is a variable that contains the memory location of another variable. The
syntax is as shown udow. You start by specifying the type of data stored in the location
identified by the pointer. The asterisk tells the compiler that you are creati
ng a pointer
variable. Finally you give the name of the variable,

type * variable name
Example:

int *ptr;
float
'string;

Address operator:

Once we declare a pointer variable we must point it to something we can do this by
assigning to the pointer the addre
ss of the variable you want to point as in the following
example:

ptr=&num;

Program:

include <stdio.h>
void
changejint *,int*);

int main ()

i
inta=2,b=5;

50



108

GTU Dec. 08 Paper with Answer

printfTBefore i a=%d,b=%d
\
n",a,b);
change(&a,&b);

printff After : a
=%d,b=%d
\
n",a,b);
return 0;

}

void change(int *a,int *b){
*a +=• *b;
*b = *a
-
*b;
*a =
*a
-
*b;
I

ii) List out the categories of functions. Explain

any one category with example.

05

Ans:

Types of functions:

A function may belong to any one of the foll
owing categories:

1.

Functions with no arguments and no return values.

2.

Functions with arguments and no return values,

3.

Functions with arguments and return values.

Functions with no arguments and no return values:

Let us consider the following program

/* Progra
m to illustrate a function with no argument and no return values*/

tt include

rnainQ

i

staetemtnlQ;

starlineQ;

51



Question Bank of
CPU

109

statement2();
starline(|;

1

/'function to print a message*/
state mentlQ

j

printf("
\
n Sample subprogram output");

!

sta
te men t2Q

printf("
\
n Sample subprogram output two");

starlineO

int a;

for (a=l;a<60;a+
-
t
-
)

printfr
\
n");

In the above example there is no data transfer between the calling function and the
called function. When a function has no arguments it does not recei
ve any data from
the calling function. Similarly when it does not return value the calling function does
not receive any data from the called function. A function that does not return any
value cannot be used in an expression it can be used only as indepen
dent statement.

52



Question Bank of CPU

1 ]

110


_________________

GTU_Dec. 08 Paper with Answer

iii) State difference between Structure and Union.

04

Ans:
Union allocates the memory equal to the maximum memory required by the
member of the union but structure allocate
s the memory equal to th" total memory
required by the members.

In union, one block is used by all the member of the union but in case of
structure, each member has their own memory space

All the members of the structure can be accessed at once,
where
as i
n an union only
one member can be used at a time. Another important difference is in the size allocated
to a structure and an union.
-

Structure

Union

-

More memory is occupied

-

Memory allocation is
less

-

All the members of structure

-

In union only one memor
y

can be accured at once.

can be used at a
time. •

for e.g.: struct
example

{

int integer;
float
floating_numbers;

}

the size allocated here is
sizeoff in t)+sizeof (float);
where as in an union

union example

!

int integer;
float
floating_nuir.bers;

I

s
ize allocated is the size of the highest member.

so size is=sizeof(flo;>t);

OR
Q
-
4) do as directed.

i) Write a program to find out sum of 6

elements of array using pointer.

05

N

^include <iostream.h>

53



Question Bank of CPU

Void mainQ

Int *
-
;ot,I,total=0;

In
t x[]={10,20,30,40,50,60:;

Tot =&x{0];

For(i=0;i<=5;i++)

i

Total= total + *tot;
Tot++;

ii) What is scope, visibility and life time of variables?

Explain static variable with example.

05

The
lifetime
of a variable is the interval of time for which the varia
ble
exists; i.e.
the time from when it is created to when it is destroyed;
duration, span,
or
extent
are equivalent terms for the same thing.

It is common to find confusion between scope and
lifetime
-

thoagh they are in
cases related, they are entirely di
fferent notions:
lifetime
is to do'with a period
of time during the execution of a program, scope is to do with which parts of a
program text. In Java, lifetime is
dynamic
-

you must execute the program (or
do so in a ihought experiment) in order to determ
ine it. Scope is static
-
determinate at compile time, or by reading the program text.

In the case of local variables (local to blocks or functions), and where there are