Totel:235 Click:
1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
C++ Interview Questions And Answers
Page 2
Questions 6 What is virtual constructors/destructors?
Answer
virtual constructors/destructors : Virtual destructors It is a Bassically same as vertual fuction, Its commonly used with inheritance. Since an abstract class must contain a pure virtual method that has to be overridden, a lot of developers commonly declare their destructors pure virtual, since a destructor is sure to be implemented in every subclass.
Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. There is no virtual constructor coz virtual thing is in run time n constructor is compile time thing.
Questions 7 What is the difference between operator new and the new operator?
Answer
Many diff are there :
Operator new is bassically just like malloc and new is the conventinally new in C++. The "New" operator allocates a new instance of an object
from the heap, Its utilising the most appropriate constructor for the arguments passed. This is Like many operators in C++, The "New" operator for a
particular class can be overriden, Although there is rarely a need to do so. "Operator new" is the mechanism for overriding the default heap allocation logic.
Answer
Operator new() use for the Operator overloading but New Operator for memory allocation.
Questions 8 Difference between "C structure" and "C++ structure".
Answer
Many diff are there :
>Structure in C defines as limited to within the module and cannot be initialized outside but Structure in C++ can initialize the objects anywhere within the boundaries of the project.
> C++ have a many methods((Procedures) but in C no methods are there.
> By default C structure are Public and C++ structure are private .
> C does not support Methods inside structure but C++ does.
> In C++ structure we can add functions but in C
structure we can't.
> In C++, structure behaves like class like can add function, and can use properties on class as inheritance, virtual,etc, But in C, structure we can have only data member but not functions.
> Structures in c++ doesnot provide datahiding but a class provides.
> classes support polymorphism, But Structures don't.
Questions 9 What is the difference between "overloading" and "overriding"?
Answer
Many Diffreces are there-
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.
overridding is runtime polymorphism while overloading is compile time polymorphism.
Questions 10 Difference between a "assignment operator" and a "copy constructor"
Answer
many diff are there :
> Assignment operator assign the object of one object to another aftr the 1st object is fully created but in copy constructor it
assign the value of one object to another at the time of its creation .
> The copy constructor is use for initialising a new instance from an old instance, And is called when passing variables by value into functions
or as return values out of functions. but in Assignment operator is used to change an existing instance to have the same values as the rvalue, which means that the instance has to be destroyed and re-initialized if it has internal dynamic memory.
> Copy constructor copies a existing object to a non existing object, which we are going to create. Assignment operation can happen between two existing objects.
> The copy constructor is creating a new object. But in The assignment operator has to deal with the existing data in the object.
> Copy constructor creates shallow copy but in assignment operator creates deep copy.
> The copy constructor is called at initialising the object but the assignment operator is used to assign one object to another.
> Copy constructor donot return anything. But in
Assignment operator returns object of same type.
> The copy constructor initializes uninitialized memory, But in assigenment operator starts with an existing initialized objects.
> Copy constuctor initialize the object with the another object of same class But assignment operator can be called on objects of different classes .
Goto Page:
1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
CPP Objective Questions And Answers
CPP Objective Questions And Answers
CPP Interview Questions And Answers
CPP Interview Questions And Answers
R4R,CPP Objective, CPP Subjective, CPP Interview Questions And Answers,CPP,CPP Interview,CPP Questions ,CPP Answers