C++Server Side ProgrammingProgramming
Here we will see some important C++ interview questions.
|Introduction||C was developed by Dennis Ritchie in around 1969 at AT&T Bell Labs.||C++ was developed by Bjarne Stroustrup in 1979.|
|Language Type||As mentioned before C is procedural programming.||On the other hand, C++ supports both procedural and object-oriented programming paradigms.|
|OOPs feature Support||As C does not support the OOPs concept so it has no support for polymorphism, encapsulation, and inheritance.||C++ has support for polymorphism, encapsulation, and inheritance as it is being an object-oriented programming language|
|Data Security||As C does not support encapsulation so data behave as a free entity and can be manipulated by outside code.||On another hand in the case of C++ encapsulation hides the data to ensure that data structures and operators are used as intended.|
|Driven type||C in general known as function-driven language.||On the other hand, C++ is known as object driven language.|
|Feature supported||C does not support function and operator overloading also do not have namespace feature and reference variable functionality.||On the other hand, C++ supports both function and operator overloading also have namespace feature and reference variable functionality.|
The main differences between pointers and references are –
References are used to refer an existing variable in another name whereas pointers are used to store address of variable.
References cannot have a null value assigned but pointer can.
A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.
A reference must be initialized on declaration while it is not necessary in case of pointer.
A reference shares the same memory address with the original variable but also takes up some space on the stack whereas a pointer has its own memory address and size on the stack
What is virtual function in C++?
Virtual functions in C++ use to create a list of base class pointers and call methods of any of the derived classes without even knowing the kind of derived class object. Virtual functions are resolved late, at the runtime.
If A virtual function in a base class declared as once a member function, it becomes virtual in every class derived from that base class. So, use of the keyword virtual is not necessary in the derived class while declaring redefined versions of the virtual base class function.
What is this pointer in C++?
Every object in C++ has access to its own address through an important pointer called this pointer. The this pointer is an implicit parameter to all member functions. Therefore, inside a member function, this may be used to refer to the invoking object.
Friend functions do not have a this pointer, because friends are not members of a class. Only member functions have a this pointer.
Let us try the following example to understand the concept of this pointer −
#include Constructor called. Constructor called. Box2 is equal to or larger than Box1 Published on 03-Jan-2020 15:25:25 Advertisements
Constructor called. Constructor called. Box2 is equal to or larger than Box1
Published on 03-Jan-2020 15:25:25