Interview Questions

C++ Back

List out some of the OODBMS available.

Ans:  GEMSTONE/OPAL of Gemstone systems,ONTOS of Ontos,Objectivity of Objectivity inc,Versant of Versant object technology, Object store of Object Design,ARDENT of ARDENT software,POET of POET software.

What is the use of 'using' declaration.

Ans:  A using declaration makes it possible to use a name from a namespace without the scope operator.

Define namespace.

Ans:  It is a feature in c++ to minimize name collisions in the global name space. This namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions. Furthermore, the compiler uses the namespace signature for differentiating the definitions.

When does a name clash occur?

Ans:  A name clash occurs when a name is defined in more than one place. For example., two different class libraries could give two different classes the same name. If you try to use many class libraries at the same time, there is a fair chance that you will be unable to compile or link the program because of name clashes.

Differentiate between a template class and class template?

Ans:  Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It's jargon for plain templates. Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It's jargon for plain classes.

What is an accessor?

Ans:  An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations.

What is a modifier?

Ans:  A modifier, also called a modifying function is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also known as 'mutators'.

void main()
int a, *pa, &ra;
pa = &a;
ra = a;
cout <<"a="<
<<"> }

Ans:  Compiler Error: 'ra',reference must be initialized
Pointers are different from references. One of the main differences is that the pointers can be both initialized and assigned,whereas references can only be initialized. So this code issues an error.

class complex { double re; double im; public: complex() : re(0),im(0) {} complex(double n) { re=n,im=n;}; complex(int m,int n) { re=m,im=n;} void print() { cout< < }; void main(){ complex c3; double i=5; c3 = i; c3.print(); }

Ans:  5,5
Though no operator= function taking complex, double is defined, the double on the rhs is converted into a temporary object using the single argument constructor taking double and assigned to the lvalue.

class complex{ double re; double im; public: complex() : re(1),im(0.5) {} bool operator==(complex &rhs); operator int(){} }; bool complex::operator == (complex &rhs){ if((this->re == && (this->im == return true; else return false; } int main(){ complex c1; cout<< c1; }

Ans:  Garbage value
The programmer wishes to print the complex object using output re-direction operator,which he has not defined for his lass.But the compiler instead of giving an error sees the conversion function and converts the user defined object to standard object and prints some garbage value.