Saturday, September 11, 2010

C++ Interview Questions

1. What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

Ans: virtual

2. What do you mean by binding of data and functions?

Ans: Encapsulation.

3. What is the difference between an object and a class?

Ans: Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.

- A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change.
- The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed.

- An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.

4. What is a class ?

Ans: Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.

5. What is friend function ?

Ans: As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition.

6. Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

Ans: Mergesort always makes recursive calls to sort subarrays that are about half size of the original array, resulting in O(n log n) time.

7. What is abstraction?

Ans: Abstraction is of the process of hiding unwanted details from the user.

No comments: