You are on page 1of 67

For free study notes log on: www.gurukpo.

com
Biyani's Think Tank
Concept based notes
Principal of Programming
Language
(B.Tech )



Amrish Sharma
Deepti Gupta
Asst. Professor
Deptt. of Engineering
Biyani International Institute of Engineering and Technology






2

For free study notes log on: www.gurukpo.com
Published by :
Think Tanks
Biyani Group of Colleges


Concept & Copyright :
Biyani Shikshan Samiti
Sector-3, Vidhyadhar Nagar,
Jaipur-302 023 (Rajasthan)
Ph : 0141-2338371, 2338591-95 Fax : 0141-2338007
E-mail : acad@biyanicolleges.org
Website :www.gurukpo.com; www.biyanicolleges.org

Edition : 2013








Leaser Type Setted by:
Biyani College Printing Department
While every effort is taken to avoid errors or omissions in this Publication, any mistake or
omission that may have crept in is not intentional. It may be taken note of that neither the
publisher nor the author will be responsible for any damage or loss of any kind arising to
anyone in any manner on account of such errors and omissions.

For free study notes log on: www.gurukpo.com
PPL 3





Preface

I am glad to present this book, especially designed to serve the needs of the students. The
book has been written keeping in mind the general weakness in understanding the fundamental
concepts of the topics. The book is self-explanatory and adopts the Teach Yourself style. It is
based on question-answer pattern. The language of book is quite easy and understandable
based on scientific approach.
Any further improvement in the contents of the book by making corrections, omission and
inclusion is keen to be achieved based on suggestions from the readers for which the author
shall be obliged.
I acknowledge special thanks to Mr. Rajeev Biyani, Chairman & Dr. Sanjay Biyani, Director
(Acad.) Biyani Group of Colleges, who are the backbones and main concept provider and also
have been constant source of motivation throughout this Endeavour. They played an active role
in coordinating the various stages of this Endeavour and spearheaded the publishing work.
I look forward to receiving valuable suggestions from professors of various educational
institutions, other faculty members and students for improvement of the quality of the book. The
reader may feel free to send in their comments and suggestions to the under mentioned
address.

4

For free study notes log on: www.gurukpo.com

Syllabus



For free study notes log on: www.gurukpo.com

Unit I
Programming Language Overview

Q.1 What do you understand by programming language ?
Ans An artificial language used to write instructions that can be translated into machine
language and then executed by a computer.

Q.2 Explain the features of programming language ?
Ans
1 . Low Level Features :
1. C Programming provides low level features that are generally provided by the Lower level
languages. C is Closely Related to Lower level Language such as Assembly Language.
2. It is easier to write assembly language codes in C programming.
2 . Portability :
1. Programs are portable i.e they can be run on any Compiler with Little or no Modification
2. Compiler and Preprocessor make it Possible for Program to run it on Different PC
3 . Powerful
1. Provides Wide verity of Data Types
2. Provides Wide verity of Functions
3. Provides useful Control & Loop Control Statements
4 . Bit Manipulation
1. C Programs can be manipulated using bits. We can perform different operations at bit
level. We can manage memry representation at bit level.
2. It provides wide verity of bit manipulation Operators. We have bitwise operators to
manage Data at bit level.
5 . High Level Features :
6

For free study notes log on: www.gurukpo.com
1. It is more User friendly as compare to Previous languages. Previous languages such as
BCPL,Pascal and other programming languages never provide such great features to
manage data.
2. Previous languages have there pros and cons but C Programming collected all useful
features of previous languages thus C become more effective language.
6 . Modular Programming
1. Modular programming is a software design technique that increases the extent to which
software is composed of separate parts, called modules
2. C Program Consist of Different Modules that are integrated together to form complete
program
7 . Efficient Use of Pointers
1. Pointers has direct access to memory.
2. C Supports efficient use of pointer .
Q.3 What are the programming paradigms ?
Ans A way of conceptualizing what it means to perform computation and how tasks to be
carried out on the computer should be structured and organized.
Imperative : Machine-model based
Functional : Equations; Expression Evaluation
Logical : First-order Logic Deduction
Object-Oriented : Programming with Data Types
Imperative
Imperative programs tells the details of HOW the results are to be obtained, in terms of
the underlying machine model. It contains both the specification and the implementation
details, inseparably inter-twined.
Imperative Style
i := 0; sum := 0;
while (i < n) do
i := i + 1;
sum := sum + i
end;

For free study notes log on: www.gurukpo.com
Storage efficient
Functional
1) Program: a collection of function definitions (m/c independent).
2) Computation by term rewriting.
3) Recursion.
4) Assign-only-once variables.
Functional Style
func sum(i:int) : int;
if i = 0
then 0
else i + sum(i-1)
end;
No Side-effect
Logic Programming
Integrates Data and Control Structures
edge(a,b).
edge(a,c).
edge(c,a).
path(X,X).
path(X,Y) :- edge(X,Y).
path(X,Y) :- edge(X,Z), path(Z,Y).


Declarative Programming
A logic program defines a set of relations. This knowledge can be used in various ways by
the interpreter to solve different queries.
Q.4 What is the difference between procedural and object-oriented programming ?
8

For free study notes log on: www.gurukpo.com
Ans
Procedural Object-Oriented
1) Emphasis on procedural
abstraction.

1) Emphasis on data abstraction.

2) Top-down design. 2) Bottom-up design
3) Step-wise refinement. 3)Reusable libraries.
4) Suited for programming in the
small.

4) Suited for programming in the large.


Q.5 Explain the structure of computer ?
Ans A computer consists of three main parts:
1) Processor (CPU)
2) Main-memory system
3) I/O system

The CPU consists of a control unit, registers, the arithmetic and logic unit, the instruction
execution unit, and the interconnections among these components. The information
handled by a computer.

Instruction
Govern the transfer information within a computer as well as between the computer and
its I/O devices Specify the arithmetic and logic operations to be performed

Data
Numbers and encoded characters that are used as operands by the instructions.
ALU
Most computer operations are performed in the arithmetic and logic unit (ALU) of the
processor For example, consider two numbers stored in the memory are to be added They
are brought into the processor, and the actual addition is carried out by the ALU. Then
sum may be stored in the memory or retained in the processor for immediate use. Typical
arithmetic and logic operation are
1) Addition,
2) subtraction
3) multiplication
4) division

For free study notes log on: www.gurukpo.com
5) comparison,
6) complement, etc.

When operands are brought into the processor, they are stored in high-speed storage
elements called registers. Each register can store one word of data.

Control Unit

The control unit is the nerve center that sends control signals to other units and senses
their states.Thus the control unit serves as a coordinator of the memory,
arithmetic and logic, and input/output units. The operation of a computer can be
summarized as follows:

The computer accepts information in the form of programs and data through an input unit
and stores it in the memory. Information stored in the memory is fetched, under program
control, into an ALU, where it is processed
Processed information leaves the computer through an output unit. All activities inside the
machine are directed by the control unit.




Q.6 What are the operations of computer ?
10

For free study notes log on: www.gurukpo.com
Ans Computer system can do various works but some important among them are:-
1) I/O devices and the CPU can execute concurrently.
2) Each device controller is in charge of a particular device type.
3) Each device controller has a local buffer.
4) CPU moves data from/to main memory to/from local buffers
5) I/O is from the device to local buffer of controller.
6) Device controller informs CPU that it has finished its operation by causing an
interrupt.

Q.7 Give the history of programming language ?
Ans


For free study notes log on: www.gurukpo.com


Q.8 What do you mean by syntax in programming language?
Ans Syntax refers to the ways symbols may be combined to create well-formed sentences (or
programs) in the language. Syntax defines the formal relations between the constituents of
a language, thereby providing a structural description of the various expressions that make
up legal strings in the language. Syntax deals solely with the form and structure of
symbols in a language without any consideration given to their meaning.

Q.9 What do you mean by semantics in programming language ?
12

For free study notes log on: www.gurukpo.com
Ans Semantics reveals the meaning of syntactically valid strings in a language. For natural
languages, this means correlating sentences and phrases with the objects, thoughts, and
feelings of our experiences. For programming languages, semantics describes the behavior
that a computer follows when executing a program in the language. We might disclose
this behavior by describing the relationship between the input and output of a program or
by a step-by-step explanation of how a program will execute on a real or an abstract
machine.



For free study notes log on: www.gurukpo.com
Unit II
Implementation of Elementary & Structured
Data Types


Q.1 Explain the concept of Array ?
Ans A Arrays is a collection of homogenous data elements (data types) describing by single
name.
Arrays is three types:-
1) One-dimensional Arrays
2) 2 dimensional Arrays
3) Multi-dimensional Array
The basic purpose of using Arrays is short the programming and similarly
using data in a single program.

One-D Array:- A list of items can be given a common name and the
individual items can be referred using only one sub script.
Declaration:-
Syntax:- Type array name [Array size];
Ex:- int a [5];
Or
Int a [5] = {2, 4, 5, 6, 7}

Int a [ ];
Double range
2.22507 e
-308
to 1.797669 e
+308

Long double;
2.22507 e
+308

Accessing Element of array. The C language using single index to access
individual element in a one dimensional array
Ex:- int marks [10]
for (i=0; I <10; i
++
)
{
scanf ( % d, & marks [1]);
}
2-D Arrays:- row, column
For (i = 0; i < 10; i
++
)
14

For free study notes log on: www.gurukpo.com
{
For (j=0; j<10; j
++
)
Scanf ( % d, & a [1] [2]



Program in 2-D Array


Q.2 WAP to Add two matrix
Ans # include <conio.h>
Void main ( )
{
Int a [10] [10], b [10] [10], C[10] [10];
Printf (Enter the no. of row and col);
Scanf ( % d % d, pn, & m;
Printf (Enter the element of A);
For (I = 0; kn; i
++
);
{
For (j = 0; j < m; j
++
);

{
Scanf ( % d %d, & a [i] [j]
}
}
printf (Enter the element of B);
for (i=0; i<n; i
++
)
{
for (j=0;j<m;j
++
)
{
scanf ( % d, & b [i] [j]);
for (I = 0; i<n;i
++
) & for (j = 0; j<m; j
++
)
C [i] [j] = a [i] [j] + b [i] [f]
printf (Three result of C);
for (I = 0; i<n; i
++
)
{
for (j = 0; j<n;j
++
) C [i] [j] = a [i] [j] + b [i] [f]
printf ( % d, & C [i] [j]);
}
printf (/n);
}
getch ( );
}

Q.3 Write a program in C find the maximum element in array.
Ans

For free study notes log on: www.gurukpo.com
Void main ( )
{
Int n, x [10], small, I;
Cont <<how many no.s you want to enter;
Cin<< n;
Cont <<Ener The No;
For (i=0;i<n;i
++
)
{
Cin >> x [i];
}
Small = x [0];
For (i=0; I,n;i
++
)
{
If (x [i] = = small)
{
Small = x [i];
}
}
Cont << smallest no. is<<small;
Getch ( );
}
}


Q.4 What do you understand by linked lists ?
Ans A linked list is a complex data structure, useful in systems or applications programming.
A linked list is comprised of a series of nodes, each node containing a data element, and
pointer to the next node, EXAMPLE,
-------- --------
| data | | data |
|--------| |--------|
| pointer| | pointer| ---> NULL

-------- --------


16

For free study notes log on: www.gurukpo.com


A structure which contains a data element and a pointer to the next node is created by,

struct list {
int value;
struct list *next;
};
This defines a new data structure called list (actually the definition of a node), which
contains two members. The first is an integer called value. The second is called next,
which is a pointer to another list structure (or node). Suppose that we declare two
structures to be of the same type as list, eg,

struct list n1, n2;
The next pointer of structure n1 may be set to point to the n2 structure by

/* assign address of first element in n2 to the pointer next of the n1 structure */
n1.next = &n2;
which creates a link between the two structures.
Program to illustrate linked lists

#include <stdio.h>
struct list
{

int value;
struct list *next;
};

main()
{


For free study notes log on: www.gurukpo.com
struct list n1, n2, n3;
int i;

n1.value = 100;
n2.value = 200;
n3.value = 300;
n1.next = &n2;
n2.next = &n3;
i = n1.next->value;
printf("%d\n", n2.next->value);
}

Types of Linked List
1. Singly Linked List :- there is a head pointer, and one next pointer per element. The
last element's pointer is null. This type of list can be traversed in only one direction.

2. Doubly Linked List :- there is a head pointer, and each element contains two
pointers, one to the previous element and one to the next element. This type of list can
be traversed in two directions, making insertion and deletion a bit easier, at the cost of
extra memory.
18

For free study notes log on: www.gurukpo.com



3. Circular List :- the same as Singly or Doubly linked, except that the last element's
pointer points back to the first element's pointer. These types of lists are often used as
queues.


Q.5 Explain the concept of Structures ?
Ans It is the collection of different data types in a program. A structure is a heterogences
collection of related fields, here fields are called structure member or structure element
every field has different data types. A structure is a collection of variables under a single
name.
or
Title of Block
C Program
C
++

Programming
Java
Author
Dannie Retina
Vikas Thapa
Black Brok
Page
400
599
900
Price
300/-
400
700/-

so
Field name Type Width
Title Char 20
Author Char 20

For free study notes log on: www.gurukpo.com
Page int 10
Price float 7.2

- Structure has a unique keywords that is struct
-
Program Syntax:-
struct Library
{
char title [20];
char author [20];
int pages [10];
float price [7.2];
};
Example.:-
Struct student
{
char name [20];
int roll no [2];
float marks [2.5];
char address [20];
};

- Syntax:-
Struct structure-tag
{
Data type-1 Structure elemend-1;
Data type-2 Structure elemend-2;
Data type-3 Structure elemend-3;
Data type-4 Structure elemend-4;
};

Main ( )
{
Struct structure-tag V
1
, V
2
-----V
n
;
Local declaration;
Executable statement;
}
Or
Struct structure-tag
{
Data types
} variables list;

Main ( )
20

For free study notes log on: www.gurukpo.com
{
Executable
}

Or

Main ( )
Struct structure tag;
{
data type stat element;
};
Struct structure tag list of variables;





Q.6 Difference between structure & array.
Ans

S.No. Array Structure
1. An array is a collection of same
data types.
Collection of different data types.
2. It has declaration only It has declaration & definition.
3. In array there is no keyword. Struct keyword in structure
Ex.:- int a [10] Ex.:- struct structure
4. An array cant have bit field. An a structure have many bit fields.
5. An array have fix memory An a structure memory can be change
dynamically.
6. Adding, deleting an element in the
array is very difficult task and it
takes much of time.
Adding & deleting is done very smoothing
or easy in a structure and less of time

Structure and Array:-
Structures have two type of view within the array the two type relations between array and
structure is finding.
1> Array of a structure
2> Array within structure
1. Array of structure:- An array of a structure of I-D & multi Dimension are declared
by only changing the structure variables from fundamental type to an array with no
change in the structure declaration.
Syntax:- for I-D
Struct structure-tag variable name [row size]
For 2-D Array:-
Struct structure-tag variable name [row size] [col size];
2. Array with in structure;- 1-D

For free study notes log on: www.gurukpo.com
Struct Structure-tag
{
Data type-1 member-element1;
Data type-2 member-element [size];
} variable-list;
2-D
Struct structure: tag
{
Data type-1 member element;
Data type-2 member element [row size] [col size];
}
Variable-list;



Nesting Structure:-
A structure can be embedded with in another structure or when a structure is declared &
processed with in another structure. If is called nesting of structure or structure within
structure.
It is used when structure is too lengthy so we sub divided the structure two or more parts
in the sub structure and elements of a structure.
Syntax:-
Eg- Struct tag1
{
Member element-1;
- - - - - - - - -
Struct tag-2
{
Member element-2;
}
Member element-n;
} VI;
Member element-m;
} V2;
Structure and pointer or Structure to pointer:- A structure can by it address by using
the pointer with structure. We use pointer with structure through a structure variable.
Syntax:- Struct. tag
{
type 1 member1;
- - - - - - - - - - - - -;
type member n;
} V
1
*P;
Where V is the structure variable and P is the pointer variable.
Ex.:- Struct student
{
Int rin;
22

For free study notes log on: www.gurukpo.com
Char name [20];
Char address [30];
Float fees;
} S, *P;
Or
(*P),rin;
(*P).name;
(*P). address;
(*P). fees;
2> Structure to function or Structure and function:-
Structure can be implemented with the function easily for the process, passing of
arguments take place similar to the array and variables.
The relationship of structure with the function can be explain by three types.
1. Passing structure to a function
2. Function returning structure
3. Passing array of struct to function
1. Passing structure to a function:- Similar to passing of array or variable;
structure can be passed to the function as argument.
Syntax:-
Type specifier function-name (stu.variable);/*as actual argument*.
Type specifier function.name (stu.variable);/*as formal argument*.
Structure tag name structure variable
{
- - - - - - - - - - -
- - - - - - - - - - -
}
- - - - - - - - - - -
- - - - - - - - - - -
2. Function returning structure:- All the values can be compute in the function
program and return a combination value of a structure back. The can be
declaration in the structure format. It has no return type.
3. Passing array of a structure to function:-
A complete complicated passing of an array of a structure to the function is a
difficult job. But the passing of array become very easy by using the passing of
array as an individual element.

Q.7 Explain the concept of files ?
Ans A file is a collection of bytes stored on a secondary storage device, which is generally a
disk of some kind. The collection of bytes may be interpreted, for example, as characters,
words, lines, paragraphs and pages from a textual document; fields and records belonging
to a database; or pixels from a graphical image.
There are two kinds of files that programmers deal with text files and binary files. These
two classes of files will be discussed in the following sections.

For free study notes log on: www.gurukpo.com
ASCII Text files
A text file can be a stream of characters that a computer can process sequentially. It is not
only processed sequentially but only in forward direction. For this reason a text file is
usually opened for only one kind of operation (reading, writing, or appending) at any
given time.
Binary files
A binary file is no different to a text file. It is a collection of bytes. In C Programming
Language a byte and a character are equivalent. Hence a binary file is also referred to as a
character stream, but there are two essential differences.
1. No special processing of the data occurs and each byte of data is transferred to or from the
disk unprocessed.
2. C Programming Language places no constructs on the file, and it may be read from, or
written to, in any manner chosen by the programmer.
Creating a file and output some data
/* Program to create a file and write some data the file */

#include <stdio.h>

Void main( )
{
FILE *fp;
char stuff[25];
int index;
fp = fopen("TENLINES.TXT","w"); /* open for writing */
strcpy(stuff,"This is an example line.");
for (index = 1; index <= 10; index++)
fprintf(fp,"%s Line number %d\n", stuff, index);
fclose(fp); /* close the file before ending program */
}
Q.8 Explain the datatypes ?
Ans

A data types is very important part of programming language data types are of 3 types.

1) Built in type 2) User define data type 3) Described type
a) Integer type a) class a) array
i) int b) struct b) function
24

For free study notes log on: www.gurukpo.com
ii) Char c) Union c) Pointer
b) Floating type d) enum d) Reference
i) Float
ii) Double
c) Void
d) Boolean
Difference between C language and C
++
language

C Language C
++
Language

1) In C stdio is header file 1) In C
++
rostrum is header file
2) C = Extension of C Language 2) CPP = Extension of C
++
3) Top down approach 3) bottom up approach
4) Scanf = input 4) Cin for input
5) Printf = output 5) Cout for output
6) n for new line 6) Enol for new lilne
7) 35 keywords 7) 63 keywords
8) data is not secure 8) data is secure using access modifiers
9) Comment single 9) Multiple comment
/* /* /* -------*/ /* ---------*/ /* ---------*/
10) No other facilities are 10) Many facilititi fiespilce
available for reasoning code => Inneritance
=> Polymorphsim
=> Class & object
=> Security
=> Encapsulation
=> Abstraction
=> Message Passinge



For free study notes log on: www.gurukpo.com
Unit III
Sequence of Controls

Q.1 Explain the conditional statements ?
Ans
Decision making statement are the conditional statements that are needed to alter the
sequence of statement in the program depends on some condition.
On the absence of decision making statement program execute in serial fashion statement
by statement.

Decision making are of 4 types.

If Statement
If else statement
The if else if statement (nesting if else & adder if else)
The switch case
1. The if statement-

Syntax:-
If (condition)
{ }
Eg:- if (a >b)
{ }
Statement a is greater
- The if statement is used to execute/skip a dope of statement on the basis of true or false of
a condition.
2. If else statement-
Syntax:- if (condition) eg if (a >b)
{ {
Stat ; a is greatest
} }
Else else
{ {
Stat; b is greatest
Stat; }
}
- If the condition within if is true, all the statements within the block are execute, else they
are skipped & else part get execute.
Example-
If ( a % 2 = 0)
else
{
26

For free study notes log on: www.gurukpo.com
A is add;
}
3. Nesting if else:-
Syntax:-
If (condition) or if (cond)
{ {
If (condition) if (cond)
{ {
Statement; Stat;
Statement; stat;
} }
else else
{ {
Statement; Stat:
Statement; stat:
} }
} }
Else
{ stat;
Stat;
}
Greater of 3 no.-
# include <iostream.h>
void main ( )
{
int x, y, z;
cont < < Enter three no.;
cin >> X >> Y >> Z;
If ( (x = = y) & & ( Y = = Z) )
cout << All are equal;
{
If (x>y)
{
If (x> z)
Cont << x is max;
Else
Cont << z is max;
}
Else
If ( Y > Z )
Cont < < Y is max i
Else
Cont << Z is max;
}
}


For free study notes log on: www.gurukpo.com


Q.3 Write a program in CPP to check enter year no. Is leap year or not leap year
Ans
# include <iostream.h>
Void main ( )
{
Int year
Cont <<Enter the year
Cin >> year;
If (year % 400 = = 0)
Cont << leap year.
}
Else
Cont << not leap year.
{
If (year % 4 = = 0)
Cont <<leap year
}
getch ( );
}

Q. 4 W.A.P. in C
++
arrange 3 no in ascending order.
Ans
Max term logic mid term =
If (a> b & & a> c) (a + b + c) (min + max)
A is max; min term.
If ( b> a & & b> c)
B is max;
If (c >a & & c> a)
C is max;
Cont << max << mid << min
Break;
- - - - - - - - - - - -
- - - - - - -- - - - -
Default;
}

Q.5. Check enter number is enter character is vowel or not vowel.
Ans
# include < iostream.h>
< c type.h>
Void main ( )
{
Char char ch;
Cont << Enter the char.
28

For free study notes log on: www.gurukpo.com
Cin > > ch;
Ch = to lower (ch);
Switch (ch)
{
Default;
Cont << not a vowel;
break;
Case a;
Case e;
Case I;
Case o;
Cout << it is a vowel;
}
getch ( );
}

Q.6 What do you understand by loops ?
Ans Looping is a process in which set of statement are excuted repetely for a finite and infinite
no. of times.
A loop is a block of statement which are executed again and again till a specify condition
is not stratify


Loop are three types:-
(1) While
(2) For
(3) Do-while
While
Syntax:- while (cond.)
{
Stat;
}
To print 1 to 10 using while loop.
int t = 1,
While ( t < < = 10)
{
Cont <<t <<endl;
t
++
;
}
int t = 10
While ( t + > =1)
{
Cont << t << endl;
t
- -
;
}

For free study notes log on: www.gurukpo.com

The statement inside { } is called body of the while loop if no { } are there then only the
first statement after the while is consider as the body of while loop.
For loop:-

Syntax:- for (initialization; condition; increment./decrement)
{
Stat;
Stat;
}
To print 1 to 10 using for loop
Example

int i
For (I = 1; I < = 10; i
++
)
{
Cont << I < < endl;
}
Nesting for:-

Syntax-
For (initialization; condition; increment/decrement)
{
For (initialization; cond; incre/decre)
{
Stat;
}
Stat;
}


* do while:-

Syntax:-
do
{
Stat;
Stat;
} while (condition);

The do while loop is similar to the while loop with the difference that the
condition is checked at the end.
It is also called bottom testing loop or exit control loop.
Regardless of the condition at the end of block the loop run at least once
1 to 10

30

For free study notes log on: www.gurukpo.com
# include <iostream.h>
# include <conio.h>
void main ( )
{
Int a;
Cont << a << endl;
a
++
;
}
While (a<=10);

Q.7 Write a program in CPP in following statement
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
Ans

# include < iostream.h>
# include < conio.h>
Void main ( )
{
Int line, Row, Col;
Cont << Enter the no. of lines.
Cin >> line;
For (row=`; row < = line; row
++
)
{
For (col=1; col <=row; col
++
)
{
Cont << < < row;
}
Cont <<Vn;
}

Getch ( );
}

Q.8 Write a program in CPP in following statement

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
Ans

For free study notes log on: www.gurukpo.com

# include < >
Void main ( )
{
Decre ( );
Cont << enter the no. of line.;
Cin << line;
For (row = 1; row < = line; row ++)
{
Cont << /n;
For (col = 1; col < = row; col
++
)
If (row % 2 = 0)
Cont << ( col % 2);
Else
Cont << (col % 2);
}
Getch ( );
}

Q.9 Explain the concept of Exception handling ?
Ans
An exception is a problem that arises during the execution of a program. An exception can
occur for many different reasons, including the following:
A user has entered invalid data.
A file that needs to be opened cannot be found.
A network connection has been lost in the middle of communications, or the JVM has
run out of memory.
The Exception class has two main subclasses : IOException class and RuntimeException
Class.

32

For free study notes log on: www.gurukpo.com


There are various types of exception, they are :-

a. ArithmeticException Arithmetic error, such as divide-by-zero.
b. ArrayIndexOutOfBoundsException Array index is out-of-bounds.
c. ArrayStoreException Assignment to an array element of an incompatible type.
d. ClassCastException Invalid cast.
e. IllegalArgumentException Illegal argument used to invoke a method.
f. IllegalMonitorStateException Illegal monitor operation, such as waiting on an
unlocked thread.
g. IllegalStateException Environment or application is in incorrect state.
h. IllegalThreadStateException Requested operation not compatible with current
thread state.
i. IndexOutOfBoundsException Some type of index is out-of-bounds.
j. NegativeArraySizeException Array created with a negative size.
k. NullPointerException Invalid use of a null reference.
l. NumberFormatException Invalid conversion of a string to a numeric format.
m. SecurityException Attempt to violate security.
n. StringIndexOutOfBounds Attempt to index outside the bounds of a string.
o. UnsupportedOperationException An unsupported operation was encountered

Q.10 What do you understand by recursive program ?

Ans When a called function is call another function this process turn in recursion.
Recursion is special case when A call itself this process is called recursion.
A recursion function is called well define function.
A recursion function should have a specify condition.
A recursion function should have smaller argument each time then the
process argument value

For free study notes log on: www.gurukpo.com
Function
SI ( ) Called function
{
Int p, r, t;
}
Void main ( )
{
Si ( )
Getch ( ); Calling function
}

No argument, no return
# include <stdio.h>
# include <conio.h>
Void SI ( )
{
float p, r, t simple interest;
printf ( Enter the value of p,r,t);
scanf (% f % f, & p, &r, &t);
Simple interest = (p x r x t)/100;
printf ( % f, Si);
}

Void main ()
{
SI();
getch ( );
}

No argument with return

# include <stdio.h>
# include <conio.h>

Float SI ( );
34

For free study notes log on: www.gurukpo.com
{
Float p,r,t;
Printf (enter the value of p,r,t);
Scanf (% f % f % f, & p, & r, &t);
Simple interest = (P * R * t)/100;
Return simple interest
}
Void main ( )
{
Float x;
x = SI ( );
printf (% f, x);
getch ( );
}

Argument with no return

# include <stdio.h>
# include <conio.h>

Void SI (float p, float r, float t)
{
Float simple interest;
Simple interest = (P x R x t)/100;
Printf (5 f. SI);
}
{
Void main ( )
{ float p,r,t;
Printf (enter the value of P,r,t);
Scanf (% f % f, &P,r & t);
SI (p;r,t)
Getch ( );
}

Argument with return

# include <stdio.h>
# include <conio.h>

Float SI (float P, float r, float t);
{
Float simple;
Simple = (P x R x t)/100
Return simple;
}

For free study notes log on: www.gurukpo.com
Void main ( )
{
Float p,r,t,x;
Printf (enter the value of p,r,t);
Scanf ( % f % f, & p, & r, t);
x = SI ( P, R, t);
Printf ( % f, x);
Getch ( );
}

Q.11 What do you understand by the concept of subprogram ?
Ans
FUNDAMENTALS OF SUBPROGRAMS
Subprograms include the following characteristics:
Each subprogram has a single entry point
There is only one subprogram execution at any given time
Control always returns to the caller when the subprogram execution terminates.

BASIC DEFINITIONS
A subprogram definition describes the interface to and the actions of the subprogram
abstraction
A subprogram call is the explicit request that the subprogram be executed.
A subprogram is active if after having been called, it has begun execution but has not
yet completed that execution.
Two fundamental kinds of subprograms are procedures and functions.
A subprogram header, which is the first line of the definition, serves several
purposes. It specifies that the following syntactic unit is a subprogram definition.
And it provides the name for the subprogram. And, it may optionally specify list of
parameters.
The parameter profile of a subprogram is the number, order and types of its formal
parameters.
The protocol of a subprogram is its parameter profile plus, if it is a function, its return
types
Subprograms declarations are common in C programs where they are called
prototypes.
DESIGN ISSUES FOR SUBPROGRAMS
Subprograms are complex structures in programming languages
36

For free study notes log on: www.gurukpo.com
An overloaded subprogram is one that has the same name as another subprogram in the
same referencing environment.
A generic subprogram is one whose computation can be don on data of different types
with different calls
PASS BY VALUE
When a parameter is passed by value, the value of the actual parameter is used to
initialize the corresponding formal parameter, which then acts as a local variable in the
subprogram this implements in-mode semantics.

Caller Callee

(sub(a, b, c)) (procedure sub(x, y, z))


a ----------call----------------- x
IN-MODE


b -------return----------------- y
OUT-MODE


c -----------call-------------- z
--------return-----------------

For free study notes log on: www.gurukpo.com
INOUT-MODE

Pass-by-value is implemented by actual data transfer
The main disadvantage of pass by value is that if physical moves are done, the additional
storage is required for the formal parameter, either in the called subprogram or in some
area outside both the caller and the called subprogram



38

For free study notes log on: www.gurukpo.com
Unit IV
Scope of Data

Q.1 What is Local Data and global Data ?
Ans Local Data :- It is the type of data that work only within the function. Its values outside
the function cant be accessible. To use the values we have to pass the value of the
variable.

Global Data :- It is the type of data that work throughout the program. The value of the
variable can be access from anywhere in the program. Example,

# include<stdio.h>

// Global variables
int A;
int B;

int Add()
{
return A + B;
}

int main()
{
int answer; // Local variable
A = 5;
B = 7;
answer = Add();
printf("%d\n",answer);
return 0;
}



Q.2 What do you understand by block structure ?
Ans In computer programming, a block is a section of code which is grouped together. Blocks
consist of one or more declarations and statements. A programming language that permits
the creation of blocks, including blocks nested within other blocks, is called a block-
structured programming language
C is not a block-structured language in the sense of Pascal or similar languages, because
functions may not be defined within other functions. On the other hand, variables can be
defined in a block-structured fashion within a function. Declarations of variables

For free study notes log on: www.gurukpo.com
(including initializations) may follow the left brace that introduces any compound
statement, not just the one that begins a function. Variables declared in this way hide any
identically named variables in outer blocks, and remain in existence until the matching
right brace. For example, in
if (n > 0) {
int i; /* declare a new i */

for (i = 0; i < n; i++)
...
}
the scope of the variable i is the true branch of the if; this i is unrelated to any i outside
the block. An automatic variable declared and initialized in a block is initialized each time
the block is entered. A static variable is initialized only the first time the block is entered.


Q.3 Explain the concept of parameter passing through function ?
Ans Group of statement in a block which have specific name is called function.
Advantage-
1. Space memory saving
2. Time saving
3. Easy to dectact the error
4. Find the modification of program
5. Increase visibility

Function-
A function is a block of code that has a name and it has a property i.e. revisable. It can be
execute from as many different points in a programming as required.
It is set of independent statement which can be utilized. Whenever it required these
independent are complete in old form.

Function

Library User define function or
or or
Standary in built function self contained function
or or
compiler function Call by value
ex:- clear ( ) ex:- add ( )
sum ( )


Categories of function:-
40

For free study notes log on: www.gurukpo.com
Functions are categories in four parts.
1. Function with no argument and no return value.
2. Function with argument and no return value.
3. Function with no argument and with return value.
4. Function with argument and with return value.

1. Function with no argument and no return value.
Syntax:-
Function 1 ( )
{
------------------
Function 2 ( );
------------------
No return
}
Functional
{
Return ( );
}
w.a.p. in C compute simple interest with no argument and no return value.
=> function with argument and no return value.
Syntax:-
With argument
Function 1 ( ) Function (x, y)
{ int x, y;
Int a, b; {
Function 2 (a, b); return;
----------- ------------
No return
----------- ------------
}
{


In this categories of function the main program will sent argument value but
called program will not return any value.


3) Function with no argument but with return value.
Syntax:-

For free study notes log on: www.gurukpo.com
no argument
Function 1 ( ) Function ( )
{
{
Function 2 ( ); return (V);
----------- ------------
Return value
----------- ------------
}
}
In this categories of function the main program will not sent any argument
value but calling will return any value.
4) Function with argument but with return value
Syntax:-
With argument
Function 1 ( ) Function 2 (a, b, c)
{ int a,b,c;
Si = function 2 )p,t, r);
------------
With return value Return (2);
}
}
(Recursive functions)




42

For free study notes log on: www.gurukpo.com
Unit V
Basics of OOPs

Q.1 What do you understand by abstract data type ?
Ans A data type can be considered abstract when it is defined in terms of operations on it, and
its implementation is hidden (so that we can always replace one implementation with
another for, e.g., efficiency reasons, and this will not interfere with anything in the
program). Thus, speaking about such a type, we leave its implementation aside
considering it irrelevant to the topic, unless we directly discuss the implementation.
I mplementation of abstract data types in C
the convention in C is to prepare two files to implement an abstract data type. One (whose
name ends in ".c") provides the implementation view; it contains the complete declaration
for the data type, along with the code that implements its associated operations. The other
(whose name ends in ".h") provides the abstract view; it contains short declarations for
functions, pointer types, and globally accessible data.
The abstract data type "stack" might then be represented as follows:
stack.h

typedef struct StackStructType *StackType;

/* Return a pointer to an empty stack. */
extern StackType InitStack ( );
/* Push value onto the stack, returning success flag. */
extern boolean Push (int k);

/* Pop value from the stack, returning success flag. */
extern boolean Pop ( );

/* Print the elements of the stack. */
extern PrintStack (StackType stack);

Q.2 What is Encapsulation ?
Ans Encapsulation is the technique of making the fields in a class private and providing access
to the fields via public methods. If a field is declared private, it cannot be accessed by

For free study notes log on: www.gurukpo.com
anyone outside the class, thereby hiding the fields within the class. For this reason,
encapsulation is also referred to as data hiding.

Q.3 Explain storage Management using stack ?
Ans Stack-based storage allocation is appropriate when the storage requirements are not
known at compile time, but the requests obey a last-in, first-out discipline. Examples:
local variables in a procedure in C/C++, Ada, Algol, or Pascal
procedure call information (return address etc).
Stack-based allocation is normally used in C/C++, Ada, Algol, and Pascal for local
variables in a procedure and for procedure call information. It allows for recursive
procedures, and also allocates data only when the procedure or function has been called --
but is reasonably efficient at the same time.
Java uses a stack for allocating frames for each method invocation. Parameters and local
variables are stored in the stack frame. Primitive types are contained within the stack
frame itself. Object references are stored in the stack frame, and point to the actual object
storage in the heap

Q.4 What is Fixed and Variable size heap storage management ?
Ans An implementation of a priority queue. It is an array A, visualized as a nearly complete
binary tree.
Max-Heap Property: The key of a node is than the keys of its
children.

Visualizing an Array as a Tree
root of tree: first element in the array, corresponding to index = 1
If a nodes index is i then:
returns index of node's parent, e.g. parent(5)=2
returns index of node's left child, e.g. left(4)=8
returns index of node's right child, e.g. right(4)=9.

44

For free study notes log on: www.gurukpo.com
Heap-Size Variable

For flexibility we may only need to consider the first few elements
of an array as part of the heap.
A[1],, A[ heap-size];

Max-Heaps vs Min-Heaps
Max Heaps satisfy the Max-Heap Property :
for all i, A[i] max{ A[left(i)] , A[right(i)]}

Min Heaps satisfy the Min-Heap Property :
for all i, A[i] min{ A[left(i)] , A[right(i)]}

Q.5 What is Garbage Collector ?
Ans In computer science, garbage collection (GC) is a form of automatic memory
management. The garbage collector, or just collector, attempts to reclaim garbage, or
memory occupied by objects that are no longer in use by the program.
Garbage collection is often portrayed as the opposite of manual memory management,
which requires the programmer to specify which objects to deallocate and return to the
memory system. However, many systems use a combination of approaches, including
other techniques such as stack allocation and region inference.
The basic principles of garbage collection are:
1. Find data objects in a program that cannot be accessed in the future
2. Reclaim the resources used by those objects
Many computer languages require garbage collection, either as part of the language
specification (e.g., Java, C#, and most scripting languages) or effectively for practical
implementation (e.g., formal languages like lambda calculus); these are said to be
garbage collected languages. Other languages were designed for use with manual
memory management, but have garbage collected implementations available (e.g., C,
C++).


For free study notes log on: www.gurukpo.com
Multiple Choice Questions

1. Inline functions are invoked at the time of

a) Run time
b) Compile time
c) Depends on how it is invoked
d) Both b and c above

2.Which of the following operators below allow to define the member functions of a class outside
the class?

a) ::
b) ?
c) :?
d) %

3.Every class has at least one constructor function, even when none is declared.

a) True
b) False

4. How do we define a destructor?

a) X~() {}
b) X() {}~
c) X() ~{}
d) ~X() {}

5. Can constructors be overloaded?

a) No
b) Yes

6. Which of the following below can perform conversions between pointers to related classes?

a) cast_static
b) dynamic_cast
c) static_cast
d) cast_dynamic

7. An abstract class can be instantiated.

a) True
46

For free study notes log on: www.gurukpo.com
b) False
8. The default access level assigned to members of a class is ___________

a) Private
b) Public
c) Protected
d) Needs to be assigned


9. Which classes allow primitive types to be accessed as objects?

a) Storage
b) Virtual
c) Friend
d) Wrapper

10. Which of the following below is /are a valid iterator type?

a) Input Iterator
b) Backward Iterator
c) Forward Iterator
d) Both a and c above

11. What is the difference between overloaded functions and overridden functions?

a) Overloading is a dynamic or run-time binding and Overriding is static or compile-time
binding
b) Redefining a function in a friend class is called function overriding while Redefining a
function in a derived class is called a overloaded fucntion.
c) Overloading is a static or compile-time binding and Overriding is dynamic or run-time
binding
d) Redefining a function in a friend class is called function overloading while Redefining a
function in a derived class is called as overridden fucnion.

12. What is shallow copy?

a) A shallow copy creates a copy of the dynamically allocated objects too.
b) A shallow copy just copies the values of the data as they are.
c) A shallow copy creates a copy of the statically allocated objects too
d) Both b and c above

13. Which of the following library function below by default aborts the program?

a) Terminate()
b) end()
c) Abort()

For free study notes log on: www.gurukpo.com
d) exit()

14. What defines a general set of operations that will be applied to various types of data?

a) Template class
b) Function template
c) Class template
d) Both a and c above

15. What happens when a pointer is deleted twice?

a) It can abort the program
b) It can cause a failure
c) It can cause an error
d) It can cause a trap

16. What is deep copy?

a) A deep copy creates a copy of the dynamically allocated objects too.
b) A deep copy just copies the values of the data as they are.
c) A deep copy creates a copy of the statically allocated objects too
d) Both b and c above

17. There is nothing like a virtual constructor of a class.

a) False
b) True

18. What is the Difference between struct and class in terms of Access Modifier?

a) By default all the struct members are private while by default class members are public.
b) By default all the struct members are protected while by default class members are
private.
c) By default all the struct members are public while by default class members are private.
d) By default all the struct members are public while by default class members are protected.

19. Vtables

a) creates a static table per class
b) creates a static table per object
c) creates a dynamic table per class
d) creates a dynamic table per object

20. C++ provides facility to specify that the compiler should match function calls with the correct
definition at the run time. This process is called as

48

For free study notes log on: www.gurukpo.com
a) Static binding
b) Dynamic Binding

21.What are the major elements in an object model?

a) Abstraction, Encapsulation and persistence
b) Hierarchy, concurrency and typing
c) Abstraction, encapsulation and hierarchy
d) Typing

22.The characteristics of an object that distinguish it from all other kinds of objects

a) Aggregation
b) Abstraction
c) Modularity
d) None of the above

23.Shallow copy is defined as

a) Member wise copying of the object
b) Same as deep copy
c) Bitwise copying of objects
d) None of the above

24.OOP allows for extension of the objects functions or of class functions. This is called as

a) Extendibility
b) Expansion capacity
c) Virtual extension
d) Scalability

25.In OOPS unit of data is called as

a) Bits
b) Blocks
c) Structures
d) Targets

26.Which of the following is not a type of object oriented abstraction?

a) Abstraction of data
b) Abstraction of function
c) Abstraction of structure
d) Abstraction of name

27.What is a const member function?

For free study notes log on: www.gurukpo.com

a) It means the function is only a read-only function
b) One which always returns the same values, given the same arguments
c) Used for constructor and destructor
d) None of the above

28.What makes a class abstract?

a) The class must not have method definitions.
b) The class must have a constructor that takes no arguments.
c) The class must have a function definition equal to zero.
d) The class which cannot be instantiated as they are mainly for inheritance.

29.What is dynamic dispatch?

a) When the function to be executed in response to a function call is determined at run-time.
b) When the function to be executed in response to a function call is determined at compile-
time.
c) When the function to be executed in response to a function call is determined at the end of
the function call.
d) None of the above

30._____________ is actually a parameterized constructor which takes some parameters in order
to create instance of a class.

a) Implicit constructor
b) Explicit constructor
c) Virtual constructor
d) Parameterized constructor

31.There is no difference between an object and an instance.

a) False
b) True

32.A package is a namespace for organizing _____________ and interfaces in a logical manner

a) instance
b) objects
c) classes
d) both b and c above

33. Common behavior can be defined in a superclass and inherited into a subclass using the
___________ keyword

a) inherit
50

For free study notes log on: www.gurukpo.com
b) extends
c) extend
d) inherits

34.Which of the following below are different Creational patterns in OO design?

a) Factory pattern
b) Single ton pattern
c) Prototype pattern
d) all of above

35.If the child object can exist beyond the lifetime of its parent, then the relationship is
____________

a) Generalization
b) Composition
c) Aggregation
d) Any of b and c above

36.Virtual inheritance is a kind of inheritance that can be used under __________

a) single inheritance
b) multi level inheritance
c) multiple inheritance
d) both a and d

37.Constructors have to be called before the main function

a) True
b) False

38.__________ allows for the separation of object interactions from classes and inheritance into
distinct layers of abstraction

a) Dispatching
b) Loosening
c) Detaching
d) Decoupling

39.The ____________ functions of the base class are also not inherited

a) Both a and d
b) Pure virtual function
c) Friend
d) Virtual


For free study notes log on: www.gurukpo.com
40.A recursive function would result in infinite recursion, if the following were left out:

a) Base call
b) Recursive call
c) Subtraction
d) Local variable declarations

41.____________ is a style of dynamic typing in which an object's current set of methods and
properties determines the valid semantics.

a) duck overcast
b) duck retype
c) duck semantic
d) duck typing

42.What is the user of parametric polymorphism?

a) A function or a data type can be written generically so that it can handle values identically
without depending on their type
b) A function or a data type can be written generically so that it can handle values identically
being dependant on their type
c) A function or a data type that can accept parameters
d) Both a and c

43.In dynamic type case a type safety check is incurred at ____________

a) Compile time
b) Run time

44.Operator overloaded is?

a) Making C++ operators works with objects
b) Giving new meaning to existing C++ operators
c) Making new C++ operator
d) Both a and b

45.Overloaded function in C++?

a) A group function with the same name
b) All have the same number and type of arguments
c) Function with same name and same number and type of arguments.
d) All of the above

46.A class having no name?

a) Is not allowed
52

For free study notes log on: www.gurukpo.com
b) Can?t have a destructor
c) Can?t have a constructor
d) Can?t be passed as an argument

47.A destructor takes?

a) One argument
b) Two arguments
c) Three arguments
d) Zero arguments

48.Constructors are use to?

a) Initialize the objects
b) Construct the data members
c) Both a and b
d) A method

49.The fields in a class of a C++ program are by default?

a) Protected
b) Public
c) Private
d) None of these

50.In C++ a function contained with in a class is called?

a) A member function
b) An operator
c) A class function
d) A method

51.__is an OOP Language?

a) Basic
b) Fortan
c) C++
d) Cobol

52. __allows you to create a derived class that inherits properties from more than one base class?

a) Multilevel inheritance
b) Multiple inheritance
c) Hybrid Inheritan
d) Hierarchical Inheritance


For free study notes log on: www.gurukpo.com
53. __feature in OOP allows reusing code?

a) Polymorphism
b) Inheritance
c) Encapsulation
d) Data hiding

54. __A class that declares or inherits a virtual function is called?

a) Encapsulation class
b) Inherited class
c) Polymorphic class
d) static class

55. __C++ header file that handles input output functions is?

a) iostream.h
b) iomanip.h
c) string.h
d) fstream.h

56. __are bound dynamically at run time?

a) static class
b) virtual function
c) friend function
d) inline function

57. __pointers are not modifiable?

a) that
b) this
c) Indirection
d) Address

58. __classes are used in cases where one class is tightly coupled to another class?

a) Abstract
b) friend
c) static
d) virtual

59. __The extension of C++ source file is?

a) txt
b) doc
54

For free study notes log on: www.gurukpo.com
c) .c
d) .cpp

60. The __ keyword/s do not apply to friend functions, as the class has no controlover the scope
of friends?

a) public
b) protected
c) private
d) both A and B

61. The extension of C++ object code is __?

a) .obj
b) .cpp
c) .ppt
d) .xls

62. __do not break encapsulation, but rather enhance a class interface?

a) Static functions
b) Friend functions
c) Dynamic functions
d) none of these

63. The function-----will return the last read character and will move the inside pointer one with-1
char?

a) putback()
b) flush()
c) peek()
d) getline().

64. __is an identifier that can be inserted into an output stream or extracted from an input stream
in order to produce a desired effect?

a) Stream
b) Manipulator
c) this
d) Flag


65. The error occurring due to missing semicolon is ___?

a) Syntax
b) Logical

For free study notes log on: www.gurukpo.com
c) Linker
d) Runtime

66. __Identify the modulators from the following list. i. endl ii. hex iii. Auto iv. Default?

a) i only
b) ii only
c) both i and ii
d) all of these


67. __Which of these manipulator is used to insert null character in a string?

a) endl
b) ends
c) unitbuf
d) setfill

68. __Which of these file open mode you use to delete all previous content in the file?

a) ios :: ate
b) ios ::in
c) ios:: app
d) ios::trunc

69. A class generated from a class template is called ------?

a) Inherited class
b) generated class
c) derived class
d) base class

70. The size of an int variable in C++ is ___bytes?

a) 4
b) 2
c) 1
d) 8

71. __is very useful when templates of template come into usage?

a) friend function
b) static function
c) typedef
d) Inheritance
e)
56

For free study notes log on: www.gurukpo.com

72. Which of these c++ feature allow you to create classes that are dynamic in terms of the types
of data they can handle?

a) Inheritance
b) Templates
c) Polymorphism
d) information hiding

73. Create the required classes by plugging in the actual type for the type parameters, this process
is commonly known as __?

a) Instantiating a class
b) encapsulation of class
c) booting of class
d) none of these

74. The exception specification is like a------ It tells the user to write exception handling code
and what exceptions to handle?

a) library file
b) function prototype
c) header file
d) built-in function

75. The size of an double variable in C++ is ____bytes?

a) 10
b) 2
c) 4
d) 8

76. Which of these exception reports a failure to allocate storage?

a) bad_cast
b) bad_typeid
c) length_error
d) none of these

77. Stack is an example for ------structure?

a) LIFO
b) FIFO
c) SISO
d) LILO


For free study notes log on: www.gurukpo.com
78. The standard sequence containers include ------
i) vector
ii) deque
iii)list
iv) stack

a) i) and ii) only
b) i),ii) and iii)
c) iii) and iv) only
d) i),ii),iii) and iv)

79.What punctuation ends most lines of C++ code?
a) . (dot)
b) ; (semi-colon)
c) : (colon)
d) ' (single quote)

80.Can I inherit the constructor and destructor of a base class?

a) No
b) Yes
81.What punctuation is used to signal the beginning and end of code blocks?
a) { }
b) -> and <-
c) BEGIN and END
d) ( and )
1) (b) 2) (a) 3) (a) 4) (d) 5) (b) 6) (c) 7) (b) 8) (a) 9) (d) 10) (d)
11) (c) 12) (b) 13) (d) 14) (b) 15) (c) 16) (a) 17) (a) 18) (c) 19) (a) 20) (b)
21) (c) 22) (b) 23) (c) 24) (d) 25) (c) 26) (d) 27) (a) 28) (d) 29) (a) 30) (a)
31) (a) 32) (c) 33) (b) 34) (d) 35) (c) 36) (c) 37) (a) 38) (d) 39) (c) 40) (a)
41) (d) 42) (a) 43) (a) 44) (d) 45) (a) 46) (b) 47) (d) 48) (a) 49) (c) 50) (a)
51) (c) 52) (b) 53) (b) 54) (c) 55) (a) 56) (b) 57) (b) 58) (b) 59) (d) 60) (d)
61) (a) 62) (b) 63) (a) 64) (b) 65) (a) 66) (d) 67) (b) 68) (d) 69) (b) 70) (b)
71) (c) 72) (b) 73) (a) 74) (b) 75) (d) 76) (d) 77) (a) 78) (b) 79) (b) 80) (b)
81) (a)


58

For free study notes log on: www.gurukpo.com
Assignment
Question 1.
void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
What is the output?

1) XAM is printed
2) exam is printed
3) Compiler Error
4) Nothing is printed

Question 2.
What is the output of the following code?
#include<stdio.h>
void swap(int&, int&);
void main()
{
int a = 10,b=20;
swap (a++,b++);
printf("\n%d\t%d\t",a, b);
}
void swap(int& x, int& y)
{
x+=2;
y+=3;
}

What is the output ?
1) 14, 24
2) 11, 21
3) 10, 20
4) Error

Question 3.


For free study notes log on: www.gurukpo.com
What will be the value of `a` after the following code is executed

#define square(x) x*x
a = square(2+3)

1) 25
2) 13
3) 11
4) 10

Question 4.
The five items: A, B, C, D and E are pushed in a stack,one after the other starting from A. The
stack is popped four times and each element is inserted in a queue. Then two elements are deleted
from the queue and pushed back on the stack. Now one item is popped from the stack.
The popped item is.

1) A
2) B
3) C
4) D

Question 5.
What is the output of the following code?

#include<stdio.h>
void main()
{
int a=0,b=0;
a = (b = 75) + 9;
printf("\n%d, %d",a, b);
}
1) 75, 9
2) 75, 84
3) 84, 75
4) None of these options

Question 6.
To delete a dynamically allocated array named `a`, the correct statement is

1) delete a;
2) delete a[0];
3) delete []a;
4) delete [0]a;

60

For free study notes log on: www.gurukpo.com
Question 7.

Evaluate !(1 && !(0 || 1)).

A. True
B. False
C. Unevaluatable

Question 8.
Find the output of the following program
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
Sample s1= 10;
SomeFunc(s1);
s1.PrintVal();
}
Answer:
Say i am in someFunc
Null pointer assignment(Run-time error)

For free study notes log on: www.gurukpo.com
Question 9.
Which is the parameter that is added to every non-static member function when it is called?
Answer:
this pointer
Question 10.
Find the output of the following program
class base
{
public:
int bval;
base(){ bval=0;}
};

class deri:public base
{
public:
int dval;
deri(){ dval=1;}
};
void SomeFunc(base *arr,int size)
{
for(int i=0; i
cout<bval;
cout<<endl;
}

int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
}

Answer:
00000
01010

62

For free study notes log on: www.gurukpo.com
Question 11.
Find the output of the following program
class base
{
public:
void baseFun(){ cout<<"from base"
};
class deri:public base
{
public:
void baseFun(){ cout<< "from derived"< };
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}

Answer:
from base
from base



For free study notes log on: www.gurukpo.com
Glossary
Abstract Class

A class that serves only as a base class from which classes are derived. No object of an
abstract base class are created base class that contains pure virtual functions is an abstract base
class.

Abstract Data Type

An abstraction that describes a set of objects in terms of encapsulated or hidden data and
operations on that data.

Abstraction

The fact of representing the essential features of something without including much detail.

Access OperationsOperation which access the state of variable or object but do not modify it.

Alias

Two or more variables that refer to same data are said to aliases of one another.
Anonymous Union

An unnamed union in C++ . the member can be used like ordinary variables.

Attribute

Property of an object. It can not exist independently of the object. Attribute may take other
objects as values.

Base Class

A class from which other classes are derived. A derived class inherit member from a base class.

Class Hierarchy

Class Hierarchy consist of a base class and derived classes. When a derived class has a single
base class, it is known a single inheritance. When a derived class has more than one base class
(multiple inheritance) , it is known as class network.

Class Object
A variable whose type is a class.(An Instance of a class).

Class Oriented

64

For free study notes log on: www.gurukpo.com
Object Based System in which every instance belongs to a class but classes may not have super
class.

Classification structure

A tree or network structure based on semantic primitives of inclusion and membership which
indicates that inheritance may implement specialization or generalization. Object may participate
in more than one such structure, giving rise to multiple inheritance.

Client

An Object that uses the service of another object called server. That is client can send
message to servers.

Composition Structure

A tree structure based on the semantic primitive part-of which indicates that certain objects
may assembled from the collection of the other objects. Objects may participate in more than one
such structure.


Constructor

A special member function for automatically creating an instance of class. This function has the
same name as the class .

Container Class

A class that contains objects of other class.

Copy Constructor

The Constructor that creates as new tool class object from an existing object of a same class.

Data Flow Diagram ( DFD )

A diagram that depicts the flow of date through a system and the process that manipulate the
data.

Data Hiding

A property where by the internal data structure of an object is hidden from the rest of the
program. The data can be accessed only by the functions declared within the class.

Data Member


For free study notes log on: www.gurukpo.com
A variable that is declared in a class declaration.

Default Argument

An argument value that is specified in a function declaration and is used if the corresponding
actual argument is omitted when the function is called.

Derived Class

A class inherits some or all of its members from another class.

Destructors

A function that is called to deallocate memory of the object of the class.

Dynamic Memory Allocation

The means by which data objects can be created as they are needed during the program
execution. Such date objects remain in existence until they are explicit destroyed. In C++,
dynamic memory allocation is accomplished with the operators new ( for creating data objects )
and delete (for destroying them).

Encapsulation
The Mechanism by which the data and functions are bound together within an object
definition.

Error State

For stream, flags that determine whether an error occurred and, and if so, give some
indication of its severity.

Extensibility

Feature that allows the extension of the existing code. This allows the creation of new
objects from existing ones.


Extraction Operator

The Operator > > , which is used to read input data from keyboard.

Format State

For stream , flags and parameters that determine how output values will be printed and how
input values will be read.

66

For free study notes log on: www.gurukpo.com
Free Store

A pool of memory from which storage for objects is allocated which is also know as heap.

Friend

A function that provides the information needed to call a function the declaration used the
name of the function, its return type and type of each argument.

Function Prototype

A function declaration is called Function Prototyping.



For free study notes log on: www.gurukpo.com
Bibliography
1. http://www.cplusplus.com/doc/tutorial/pointers/
2. http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm
.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr380.htm
3. http://www.learncpp.com/cpp-tutorial/115-inheritance-and-access-specifiers/
4. http://www.cplusplus.com/doc/tutorial/

You might also like