1. STL Containers - What are the types of STL containers?

There are 3 types of STL containers:

1. Adaptive containers like queue, stack
2. Associative containers like set, map
3. Sequence containers like vector, deque

2. RTTI - What is RTTI in C++?

RTTI stands for "Run Time Type Identification". In an inheritance hierarchy, we can find out the exact type of the objet of which it is member. It can be done by using:

1) dynamic id operator
2) typecast operator

RTTI is defined as follows: Run Time Type Information, a facility that allows an object to be queried at runtime to determine its type. One of the fundamental principles of object technology is polymorphism, which is the ability of an object to dynamically change at runtime.

3. Assignment Operator - What is the diffrence between a "assignment operator" and a "copy constructor"?

In assignment operator, you are assigning a value to an existing object. But in copy constructor, you are creating a new object and then assigning a value to that object. For example:

complex c1,c2;
c1=c2; //this is assignment
complex c3=c2; //copy constructor

A copy constructor is used to initialize a newly declared variable from an existing variable. This makes a deep copy like assignment, but it is somewhat simpler:

There is no need to test to see if it is being initialized from itself.
There is no need to clean up (eg, delete) an existing value (there is none).
A reference to itself is not returned.

5. Can you be bale to identify between Straight- through and Cross- over cable wiring? and in what case do you use Straight- through and Cross-over?

Straight-through is type of wiring that is one to connection, Cross- over is type of wiring which those wires are got switched
We use Straight-through cable when we connect between NIC Adapter and Hub. Using Cross-over cable when connect between two NIC Adapters or sometime between two hubs.

6. What are the defining traits of an object-oriented language?

The defining traits of an object-oriented langauge are:
* encapsulation
* inheritance
* polymorphism

7. What methods can be overridden in Java?

In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.

8. In C++, what is the difference between method overloading and method overriding?

Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

9. What is the difference between Mutex and Binary semaphore?

semaphore is used to synchronize processes. where as mutex is used to provide synchronization between threads running in the same process.

10. Will this C++ program execute or not?

void main()
char *cptr = 0?2000;
long *lptr = 0?2000;
printf(" %x %x", cptr, lptr);
}Will it execute or not?

For Q2: As above, won't compile because main must return int. Also, 0x2000 cannot be implicitly converted to a pointer (I assume you meant 0x2000 and not 0?2000.)

Not Excute.
Compile with VC7 results following errors:
error C2440: ‘initializing' : cannot convert from ‘int' to ‘char *'
error C2440: ‘initializing' : cannot convert from ‘int' to ‘long *'

Not Excute if it is C++, but Excute in C.
The printout:
2001 2004

In C++
[$]> g++ point.c
point.c: In function `int main()':
point.c:4: error: invalid conversion from `int' to `char*'
point.c:5: error: invalid conversion from `int' to `long int*'

in C
[$] etc > gcc point.c
point.c: In function `main':
point.c:4: warning: initialization makes pointer from integer without a cast
point.c:5: warning: initialization makes pointer from integer without a cast
[$] etc > ./a.exe
2001 2004

Download Interview PDF