
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialProgramming
4.7 Rating 30 Questions 32 mins read22 Readers

One of the latest features of C++11 are a Move Constructor and a Move Assignment operator. We know that a Copy Constructor and a Copy Assignment is used to make a copy of one object to another, the Move Constructor and Move Assignment is to shift the ownership of the resources from one object to other. This is less expensive that object to object copy. A Move Constructor and Move Assignment operator is not provided by the compiler by default and one needs to implement the same.
Though both of them perform similar tasks, the differences between a Copy Constructor and an assignment operator is as follows:
This is a frequently asked question in c++ interview questions for freshers.
Stack Unwinding happens during exception handling. During an exception occurs, the destructor is called to destroy all local objects for the place where the exception was thrown and where it was caught. An exception causes the control to pass on from a try block to the respective exception handler. The destructors for all constructed automatic objects are called at run time, which where created since the beginning of the try block. The automatic objects are destroyed in reverse order of their construction.
Note: The corresponding objects must be created before the destruction of the same, which takes place during Stack Unwinding.
The terminate() function is invoked during Stack Unwinding on a destructor for an unhandled exception.
The following example demonstrates this:
#include <iostream>
using namespace std;
struct E {
const char* message;
E(const char* arg) : message(arg) { }
};
void my_terminate() {
cout << "Call to my_terminate" << endl;
};
struct A {
A() { cout << "In constructor of A" << endl; }
~A() {
cout << "In destructor of A" << endl;
throw E("Exception thrown in ~A()");
}
};
struct B {
B() { cout << "In constructor of B" << endl; }
~B() { cout << "In destructor of B" << endl; }
};
int main() {
set_terminate(my_terminate);
try {
cout << "In try block" << endl;
A a;
B b;
throw("Exception thrown in try block of main()");
}
catch (const char* e) {
cout << "Exception: " << e << endl;
}
catch (...) {
cout << "Some exception caught in main()" << endl;
}
cout << "Resume execution of main()" << endl;
}The output of this example:
In try block In constructor of A In constructor of B In destructor of B In destructor of A Call to my_terminate
In the try block, two automatic objects are created: a and b. The try block throws an exception of type const char*. The handler catch (const char* e) catches this exception. The C++ run time unwinds the stack, calling the destructors for a and b in reverse order of their construction. The destructor for a throws an exception. Since there is no handler in the program that can handle this exception, the C++ run time calls terminate(). (The function terminate() calls the function specified as the argument to set_terminate(). In this example, terminate() has been specified to call my_terminate().)
Deep copy involves using the contents of one object to create another instance of the same class. In a deep copy, the two objects may contain ht same information but the target object will have its own buffers and resources. the destruction of either object will not affect the remaining object. The overloaded assignment operator would create a deep copy of objects.
Shallow copy involves copying the contents of one object into another instance of the same class thus creating a mirror image. Owing to straight copying of references and pointers, the two objects will share the same externally contained contents of the other object to be unpredictable.
Using a copy constructor we simply copy the data values member by member. This method of copying is called shallow copy. If the object is a simple class, comprised of built in types and no pointers this would be acceptable. This function would use the values and the objects and its behavior would not be altered with a shallow copy, only the addresses of pointers that are members are copied and not the value the address is pointing to. The data values of the object would then be inadvertently altered by the function. When the function goes out of scope, the copy of the object with all its data is popped off the stack.
If the object has any pointers a deep copy needs to be executed. With the deep copy of an object, memory is allocated for the object in free store and the elements pointed to are copied. A deep copy is used for objects that are returned from a function.
It's no surprise that this one pops up often in c++ interview questions and answers for freshers.
Name mangling is the process through which the C++ compilers give each function in the program a unique name. In C++, all programs have at least a few functions with the same name. Name mangling is a concession to the fact that linker always insists on all function names being unique. In C++, generally, programs have at least a few functions with the same name.
Example:
In general, member names are made unique by concatenating the name of the member with that of the class given the declaration:
class Bar
{
public:
int ival;
...
};ival becomes something like:
// a possible member name mangling ival__3Bar
Consider this derivation:
class Foo : public Bar
{
public:
int ival;
...
}The internal representation of a Foo object is the concatenation of its base and derived class members.
// Pseudo C++ code // Internal representation of Foo class Foo
{
public:
int ival__3Bar;
int ival__3Foo;
...
};Unambiguous access of either ival members is achieved through name mangling. Member functions, because they can be overloaded, require an extensive mangling to provide each with a unique name. Here the compiler generates the same name for the two overloaded instances(Their argument lists make their instances unique).
The main characteristics of static functions are as follows:
An inline function is a request and not a command. Hence it won't be compiled as an inline function always.
Inline-expansion could fail if the inline function contains loops, the address of an inline function is used, or an inline function is called in a complex expression. The rules for in-lining are compiler dependent.
It's no surprise that this one pops up often in C++ interview questions for experienced.
Design Patterns are reusable solutions that can be applied to recurring Object Oriented Design problems. Singleton is one such design pattern that comes under the category of a Creational Design Pattern. It can be used to design such a class which can, at most have only a single instance at any point of time and cant be instantiated further. This concept can be applied for creation of a logger or hardware interface class which can have only one instance running at all times.
Example of Singleton class that is thread-safe:
In order to make the class thread safe, one needs to only create an instance when no other instance exists as below:
class Singleton
{
public:
static Singleton* getinstance();
...
private:
static Singleton* volatile newinstance;
};
Singleton* Singleton::getinstance()
{
if (newinstance == NULL)
{
Guarder<Lock>lock(m_lock);
if (newinstance == NULL)
{
Singleton* volatile temp = static_cast< Singleton* >(operator new (sizeof(Singleton)));
Newinstance = temp;
}
}
return newinstance;
}Smart Pointers are used for better garbage collection so that there are no memory leaks. Using Smart Pointers, there is no need to call delete for any memory allocated dynamically and it gets automatically deallocated.
Smart Pointers Implementations can be found in C++11 and higher versions. C++11 libraries provide four kinds of Smart pointers namely: auto_ptr, unique_ptr, shared_ptr and weak_ptr.
The below example implements a generic smart pointer which can used for all datatypes:
#include<iostream>
using namespace std;
template <class T>
class SmartPtr
{
T *ptr;
public:
// Constructor
explicit SmartPtr(T *p = NULL) { ptr = p; }
// Destructor
~SmartPtr() { delete(ptr); }
// Overloading dereferncing operator
T & operator * () { return *ptr; }
// Overloding arrow operator so that members of T can be accessed
// like a pointer (useful if T represents a class or struct or
// union type)
T * operator -> () { return ptr; }
};
int main()
{
SmartPtr<int> ptr(new int());
*ptr = 20;
cout << *ptr;
return 0;
}Vectors and Lists are defined under C++ Standard Template Library (STL). These data structures are basically sequential containers implemented using STLs.
The differences between them are as follows:
You can make a class virtual if it is a base class that has been
passed to more than one derived class, as might happen with multiple
inheritance.
A base class can't be specified more than once in a derived class:
class B { ...};
class D : B, B { ... }; // ILLEGALHowever, a base class can be indirectly passed to the derived class more than once:
class X : public B { ... }
class Y : public B { ... }
class Z : public X, public Y { ... } // OKIn this case, each object of class Z will have two sub-objects of class B.
If this causes problems, you can add the keyword "virtual" to a base class
specifier. For example,
class X : virtual public B { ... }
class Y : virtual public B { ... }
class Z : public X, public Y { ... }B is now a virtual base class, and class Z has only one sub-object of class
B.
Constructors for Virtual Base Classes:
Constructors for virtual base classes are invoked before any non-virtual base classes. If the hierarchy contains multiple virtual base classes, the virtual base class constructors are invoked in the order in which they were declared. Any non-virtual bases are then constructed before the derived class
constructor is called. If a virtual class is derived from a non-virtual base, that non-virtual base will be first, so that the virtual base class can be properly constructed. For example, this code
class X : public Y, virtual public Z X one; produces this order: Z(); // virtual base class initialization Y(); // non-virtual base class X(); // derived class
Expect to come across this popular question in advanced C++ interview questions.
An abstract class is a class which has at least one pure virtual function. An abstract class can't be instantiated be can be overridden in a derived class as below:
//Example below:
class Base {
public:
virtual void Get() = 0;
virtual bool Get(int i) = 0;
virtual int Get(float x) = 0;
virtual ~Base() { }
};
class Derived1 : public Base {
bool value;
public:
void Get() { }
bool Get(int i) { return i;}
int Get(float x) { return (int)x;}
};
class Derived2 : public Base {
int value;
public:
void Get() { }
bool Get(int i) { return i;}
int Get(float x) { return (int)x;}
};
int main()
{
int k=5;
int temp = base->Get(k);
cout<<"temp is"<<base->Get(k)<<endl;
return 0;
}