Wednesday 11 February 2015

Important C++ Interview Questions and Answers for Freshers (Page 2)

Below are some important C++ interview questions which are asked in most MNC company interviews for beginners or professionals.

11. What do you mean by Stack unwinding in C++?
Stack unwinding in C++ is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught.

12. What are the conditions that have to be met for a condition to be an invariant of the class?
? The condition should hold at the end of every constructor.
? The condition should hold at the end of every mutator (non-const) operation.

13. Name some pure object oriented languages?
pure object oriented languages are Smalltalk, Java, Eiffel, Sather.

14. What is a node class in C++?
A node class is a class that,
? relies on the base class for services and implementation,
? provides a wider interface to the users than its base class,
? relies primarily on virtual functions in its public interface
? depends on all its direct and indirect base class
? can be understood only in the context of the base class
? can be used as base for further derivation
? can be used to create objects.
A node class is a class that has added new services or functionality beyond the services inherited from its base class.

15. What is an orthogonal base class in C++?
If two base classes have no overlapping methods or data they are said to be independent of, or orthogonal to each other. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way. The same derived class may inherit such classes with no difficulty.

16. What is a container class? What are the types of container classes in C++?
A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.

17. What is polymorphism in C++?
Polymorphism in C++ is the idea that a base class can be inherited by several classes. A base class pointer can point to its child class and a base class array can store different child class objects.

18. How can you tell what shell you are running on UNIX system?
You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -1 and look for the shell with the highest PK).

19. What is the difference between realloc() and free()?
The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

20. What is the difference between declaration and definition?
The declaration tells the compiler that at some later point we plan to present the definition of this
declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
{
for(intj=10; j > =0; j—- //function body
cout« *;
cout« endl;
}
More Questions & Answers :-

1 comment:

  1. Hi There,

    A really interesting, clear and easily readable C++ Interview Questions article of interesting and different perspectives.I will clap. So much is so well covered here.


    Using C Prog, Dev a prog that will play a number guessing game.The prog should allow users to enter their 3 numbers (between 0-9). You must store teh 3 numbers in a 1D array.

    You prog should use functions. The prog should display a simple menu to the user and each option in teh menu will be implemented by calling a separate function. You must use pointer notation to access array elements-NOT subscripts.

    1. Enter 3 selected numbers
    2. Display the contents of the 1D array containing the numbers you entered.
    3. Compare your chosen lotto numbers in teh 1D array with eh following winning numbers: 1,3, 5

    Return to the main() function how many numbers the use entered correctly and display this.

    4. Reverse the contents of the 1D array containing the numbers the user entered correctly and display this.


    Thanks a lot. This was a perfect step-by-step guide. Don’t think it could have been done better.


    Kind Regards,
    Preethi

    ReplyDelete