C++ is quite often the first Object Oriented Programming languages learnt by developers. Being one of the earliest object-oriented programming languages, it has gone on to influence many other programming languages. This also helps with the fact that if you learn C++, then learning any other object-oriented programming language becomes easy. In particular, C++ is one of the widely used programming languages in development, even after being 3 decades in existence. As a fresher in the software industry, it is important to be familiar with the basics of C++, particularly from the context of the technical interview. This page contains commonly asked technical interview questions for C++ Programming.
C++ supports both procedural as well as object-oriented programming code (also known as a multi-paradigm), whereas C is purely a procedural language. C++ is particularly oriented towards protecting data. This is done using modifiers for class members. Data in C as we know is subject to security infiltrations. In C++, more than one variable can point to the same memory location through the support for reference variables. C does not support this. C++ has built-in exception handling capabilities, whereas C does not. C++ supports function overloading where a function can have more than one definition. C does not support this option.
A class can be thought of as a blueprint of a car. The blueprint itself does not create the car. It only specifies the structure of the car, what goes where, etc. By using this blueprint, you can specify dimensions for each element, which then can help in creating a car. The car can be likened to the object. Any number of cars can be created from a blueprint. Similarly, any number of objects can be created from a class. Class is hence the definition of a datatype, where the structure of the data is specified.
Encapsulation is a mechanism used by classes to hide data from outside of the class. Both the data and functions that work with the data are encapsulated within a class. Encapsulation is also called data hiding, due to its obvious function of hiding data. Every data type within a class will have access specifiers which basically details how data can be accessed. There are 3 access specifiers – private, public and protected.
Again using the car analogy, we know that stepping on the accelerator is going to accelerate the vehicle, and releasing the accelerator will slow the vehicle down. You need not bother about the inner complexities that are involved with the accelerator. It doesn’t matter if more petrol is entering the engine or if someone behind the car gets an instruction to push harder. This is similar to the concept of data abstraction. Within a class, there could be certain data and functions that it performs. However, all we need to know (as being a part of the outside world) is what a particular class does, not how it does it.
Inheritance is the mechanism through which one class inherits the properties of another. This helps in breaking programming code into modules and reusing code which in turn helps in optimizing for memory.
Help other candidates who are preparing for technical interviews for C++ by posting questions that you were asked in your interview in the comments. Also, if there are any technical interview C++ Programming questions that you had received, let us know and we will add it to the page along with the answers.