Match Group Frequently Asked C++ Interview Questions Answers

Why Are Arrays Usually Processed With For Loop?

The real power of arrays comes from their facility of using an index variable to traverse the array, accessing each element with the same expression a[i]. All the is needed to make this work is a iterated statement in which the variable i serves as a counter, incrementing from 0 to a. length -1. That is exactly what a loop does.

What Is Polymorphism In C++? Explain With An Example?

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus '+' sign, used for adding two integers or for using it to concatenate two strings.

What Do You Mean By Pure Virtual Functions?

A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.

class Shape
{
public: virtual void draw() = 0;
};

What Is A Scope Resolution Operator?

A scope resolution operator (::), can be used to define the member functions of a class outside the class.

What Is The Difference Between An External Iterator And An Internal Iterator? Describe An Advantage Of An External Iterator?

An internal iterator is implemented with member functions of the class that has items to step through. .An external iterator is implemented as a separate class that can be "attach" to the object that has items to step through. .An external iterator has the advantage that many difference iterators can be active simultaneously on the same object.

What Are Virtual Functions In C++?

A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

What Is Abstraction In C++?

Abstraction is of the process of hiding unwanted details from the user.
Match Group Frequently Asked C++ Interview Questions Answers
Match Group Frequently Asked C++ Interview Questions Answers

Which Recursive Sorting Technique Always Makes Recursive Calls To Sort Subarrays That Are About Half Size Of The Original Array?

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

What Is Friend Function In C++?

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.

What Is A C++ Class?

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.

Suppose That Data Is An Array Of 1000 Integers. Write A Single Function Call That Will Sort The 100 Elements Data [222] Through Data [321]?

quicksort((data + 222),100);

What Is The Difference Between An Object And A Class?

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.

What Are 2 Ways Of Exporting A Function From A Dll?

1 .Taking a reference to the function from the DLL instance.
2. Using the DLL 's Type Library.

What Do You Mean By Binding Of Data And Functions?

Encapsulation.

What Is The Word You Will Use When Defining A Function In Base Class To Allow This Function To Be A Polimorphic Function?

virtual.

What Is Virtual Class And Friend Class?

Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database than main() has.

What Is Boyce Codd Normal Form In C++?

A relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form a-> , where a and b is a subset of R, at least one of the following holds

a- > b is a trivial functional dependency (b is a subset of a).
a is a superkey for schema R.

What Is A Copy Constructor And When Is It Called?

A copy constructor is a method that accepts an object of the same class and copies it's data members to the object on the left part of assignement

class Point2D{ int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0),y(0){} //default (no argument)constructor
public Point2D( const Point2D & );
};
Point2D::Point2D( const Point2D & p )
{
this->x = p.x; this->y = p.y;
this->color = p.color;
this->pinned = p.pinned;
}
main()
{
Point2D MyPoint;
MyPoint.color  = 345;
Point2D AnotherPoint = Point2D( MyPoint);
// now AnotherPoint has color = 345

What Do You Mean By Inheritance?

Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.

Can We Define A Constructor As Virtual In C++?

No, we cannot define constructors as virtual because constructors have the same name as their classes and no two constructors of base-derived classes can have the same name. So, when we initialize an object of the base or derived class with the help of virtual constructors, the base constructor is invoked instead of the derived constructor. Therefore, it is not possible to define a constructor as virtual.

Can We Declare A Base-class Destructor As Virtual?

Yes, we can declare a base-class destructor as virtual that makes all derived-class destructors as virtual even if they do not have the same name as base-destructor. The problem arises when the derived class's pointer refers to a base class. For this reason, the base class destructor should be declared as virtual so that the appropriate destructor is called on calling the delete method of the base class object.

How Does A Copy Constructor Differs From An Overloaded Assignment Operator?

A copy constructor uses the value of an argument to construct a new object. We can use an overload assignment operator to assign the value of an existing object of the same class to another existing object in that class.

Define The Process Of Error-handling In Case Of Constructor Failure?

If the constructor does not have the return statement, then it indicates failure in handling the error by throwing an exception.

What Is A Default Constructor?

A zero-argument constructor or a constructor in which all the arguments have default values is called a default constructor.
For example
A Al; // default constructor called.

Define The Process Of Handling In Case Of Destructor Failure?

In order to handle a failed destructor, you need to write a message to a log file; however, do not throw an exception. There is a rule in C++ that exception cannot be thrown from a destructor, which is called when the process of "stack unwinding" occurs in other exceptions. For example, if someone says throw waste files(), the stack frames between the throw waste files() and the catch (waste files) will get popped. This is known as stack unwinding. It is the process of destroying all the local objects related to those stack frames and calling destructors in case of throwing of an exception by one of those destructors. For example, if an object named Bar is thrown, then the C++ runtime system is in a neutral situation means either to avoid the Bar and end up in the catch (waste files) or ignore the function Foo and look for a catch (Bar) handler. It will call in the terminate () process to end the program.

What Is A Virtual Destructor?

Virtual destructors help in destroying objects without knowing their type. With the help of the virtual function mechanism, the appropriate destructor for the object is invoked. In the case of abstract classes, destructors can also be declared as pure virtual functions. For example, class A derives from class B. Then, on calling the derived class dynamically at the execution time, the destructor will first call the derived class that is class A, and then the base class that is class B.

It is important to note that theVirtual keyword, when used with the destructor, ensures the calling of all the derived and base class destructors and therefore helps in the proper execution and closing of the program.

Can You Explicitly Call A Destructor On A Local Variable?

No, the destructor is called when the block closes in which the local variable was created.
If a destructor is called explicitly twice on the same object, the result ends in an undefined behavior because the local variable gets destroyed when the scope ends.

What Are Shallow And Deep Copies?

A shallow copy is used to copy actual values of the data. It means, if the pointer points to dynamically allocated memory, the new object's pointer in the copy still points to items inside the old objects and the returned object will be left pointing to items that are no longer in scope. A copy of the dynamically allocated objects is created with the help of a deep copy. This is done with the help of an assignment operator, which needs to be overloaded by the copy constructor.

What Do You Understand By Zombie Objects In C++?

In a situation, where an object is created in a class, a constructor fails before its full execution. It is very difficult to ensure about the execution of the constructor whether the constructor would return a value or not. Objects that are no more required for an application are called zombie objects. These zombie objects occupy a space in the memory and wait for their termination.

Post a Comment

Previous Post Next Post