Professional Documents
Culture Documents
1. What is C++?
C++ is a general –purpose programming language with a
bias towards system programming that
- is a better C. -
supports data abstraction - supports
object-oriented programming
- supports generic programming.
Long Double
1,0
MACHINE LANGUAGE
ASSEMBLY LANGUAGE
PROCEDURE PROGRAMMING
OBJECT-ORIENTED
PROGRAMMING Layers of
software technology.
UNIT II
For eg,
Class myclass
{
int a,b;
public:
friend int sum(my class x);
};
34. What are the situations where inline expansion cannot work?
• For function returning values, if a loop, a switch or a go to exists.
• For function not returning values, if a return statements exist.
• If function contain static variables.
• If inline function are recursive.
39. What is scope resolution operator? Explain how does it work in c++?
The ::operator links a class name with a member name in order to
tell the complier what class the member belongs to. It has another use
that is it can allow access to a name in an enclosing scope that is hidden
by a local declaration of the same name.
Egname.
Eg:
Void f()
{
int I;
I=10;
………..
……..
}
It may do so by preceding the I with the :: as shown here
Void f()
{
int I;
::I=10;
……..
……..
}
43. List the restrictions that are to be followed while using unions in c++
• Union cannot inherit any other classes of any type.
• Union cannot be a base class
• No static variables can be members of a union
• A reference member cannot be used
• A union cannot have as a member any object that overloads =
operator
• No objects can be a member of a union if the object has an explicit
constructor on destructor function.
accessing:
for(I=1;I<=n;I++)
{
ob[i].get();
ob[i].disp();
}
New
• The new operator is used to create a heap memory space
for an object of a class.
Delete
• The delete operator is used to destroy the variable space
which has been created by using the new operator
dynamically.
56. What are the restrictions that have been placed on Static member
functions?
• As a function parameter.
• As a function return value.
• As a stand-alone reference.
60. What are the 2 ways in which arguments can be passed to functions?
• Call-by-value.
• Call-by-reference.
Example:
int a; // global
void f( )
{
int a; //local
a=10; //local
::a=10; //global
}
Example:
Class sample
{
int a;
public:
void print( ) { a=10*10 }
};
main( )
{
sample s,*p;
p=&s;
p->print( );
}
UNIT IV
Class derived_class_name
{
--------------
--------------//members of derived class
--------------
};
members of abc;
};
Eg : 2
Class abc: private Xyz // public derivation
{
members of abc;
};
Class_name<type>object_name(arglist);
We can use more than one generic data types in a class template.
They are declared as a comma separated list within the template
specification as show below:
Syntax:
Like template class we can use more than one generic data type
in the template statement, using comma separator
Syntax:
Template<class T1,class T2,….>
return type function name(argument of type T1,T2,…)
{
………..
//body of function
Syntax:
Template<class T>
return type classname<T> : : function name(arglist)
{
……………(function body)
…………….
}
85. Explain non-type template arguments?
Eg:
Template<class T, int size>
Class array
{
T a[size];
……..
……..
};
this templates supplies the size of the array as an argument.
Exception objects
CATCH BLOCK
Try
{
//try block;
}
catch (type 1 arg)
{
// catch block1;
}
catch (type 2 arg)
{
// catch block 2;
}
……………….
……………….
Catch (type n arg)
{
// catch block n;
}
105. What are member function adapter & pointer to function adapter?
109. What are the types of Iterators that are supported by each container
class?
• Associative container
1. set
2. multiset
3. map
4. multimap
• Derived container
1. stack
2. queue
3. priority queue
Element0Element1Element2……..Last element…
Begin() end()
All these containers stores data in a structure called tree which facilities
fast searching, deletion and insertion.
function Task
Back() Gives a reference to the last
element
Begin() Gives a reference to the first
element
Clear() Deletes all the elements
Empty() Decides if the list is empty or not
End() Gives refernce to the end of the list
Erase() Deletes elements as specified
merge() Merge two ordered list
Insert() Insert elemements as specified
Pop_back() Deletes the last element
Pop_front() Deletes the first element
Push_back() Adds an element at the end
Push_front() Adds an element at the front
Remove()
UNIT V
120. what are the important points to remember while using concrete
types?
i. Concrete types are fitted into a hierarchy of related
classes.
ii. Each concrete type can be understood in isolation with
minimal reference to other classes.
iii. If a concrete type is implemented well, programs using it
are comparable in size and speed to programs a user
would write using a hand-crafted and specialized version
of the concept.
iv. If the implementation changes significantly the interface is
usually modified to reflect the change.
v. Concrete type resembles in the built in type.
121. What are the advantages of concrete type over abstract type?
i. An individual concrete classes is easier to understand and
use then is a more general class.
ii. Concrete type is often used for classes that represent well
known data types such as arrays and list.
122. What is meant by abstract type?
i. A class is said to be abstract class that represents the
interface to a set of implementations of a common
concept.
ii. The abstract class provides the common interface to the
implementation. This means, we can use a set without
knowing which kind of implementation is used.
REPRESENTATION
HANDLE
UNIT III
9. What is constructor?
A constructor is a special member function whose task is to
initialize the objects of its class. It is special because its name is the
same as the class name. The constructor is invoked whenever an
object of its associatied class is created.
It is called constructor because it construct the values of data
members of the class.
Eg:
Class A
{
int m,n;
public:
A(int x,int y); //parameterized constructor
………..
………..
};
A : : A(int x,int y)
{
m=x;
n=y;
}
16.what are the two ways to pass values as arguments to the
constructor?
Two ways to pass values as arguments to the constructor
function when an object is declared.
By calling the constructor explicitly.
By calling the constructor implicitly.
Eg :
Explicit call:
Integer int1=integer(0,200);
Implicit call:
Integer int1(0,100);
Eg :
Explicit call:
Integer int1=integer(0,200);
Implicit call:
Integer int1(0,100);
~integer(){}
A destructor never takes any argument nor does it return any value. It
will be invoked implicity by the compiler upon exit from the program to
clean up storage that is no longer accessible. It is a good practice to
declare destrucors in program since it releases memory space for
future use.
24.Difference between constructor and destructor?
constructor destructor
1.Constructor is a ‘special’ member 1.destructor is a member function
function whose task is to initialize whose name is the same as the
the objects of its class. class name but is preceded by a
2. it construct the values of data tilde.
members of the class 2. it destroy the objects that have
been created by a constructor.
Matrix :: ~matrix( )
{
for(int i=0;i<d1;i++)
delete p[i];
delete p;
}
Example :
Complex() { } //constructor with no arg.
Complex (float a) { x=y=a;} //constructor with one arg.
Complex (float real, float imag) //constructor with two arg.
Class objects can be initialized dynamically too. That is, the initial
value of an object may; be provided during run time.
Advantages: