C++ Interview Questions and Answers for Freshers, Experienced
We are providing comprehensive set of C++ Interview Questions and Answers for Freshers and Experienced who wants to get into software industry. It’s regardless of which domain or language you would like to pursue your career in, because 90% of campus placement interviews include questions from C or C++. The main reason being a candidate who is fresh out of college is not expected to be a master of widely used languages like Java, Python, Perl etc. and most of the universities have C or C++ as a part of their curriculum. For example, in most institutions C language is being taught along with data structure course and C++ as part of Object oriented programming. So always expect questions on C/C++ in the technical interviews for fresher.
One advantage with fresher interviews is that there are only limited number of concepts and questions and the same has been repeatedly being asked over years. If you want to pursue your career in system level programming like driver development, needless to say, you should show your mastery in C/C++ interviews. Here we have identified and collected a set of frequently asked C++ interview questions and answers for experienced and freshers as well. It’s a continuously updated list, go through them, understand the concepts and excel in the interviews.
1. What is difference between C and C++ ?
- C++ is Multi-Paradigm ( not pure OOP, supports both procedural and object oriented) while C follows procedural style programming.
- In C data security is less, but in C++ you can use modifiers for your class members to make it inaccessible from outside.
- C follows top-down approach ( solution is created in step by step manner, like each step is processed into details as we proceed ) but C++ follows a bottom-up approach ( where base elements are established first and are linked to make complex solutions ).
- C++ supports function overloading while C does not support it.
- C++ allows use of functions in structures, but C does not permit that.
- C++ supports reference variables ( two variables can point to same memory location ). C does not support this.
- C does not have a built in exception handling framework, though we can emulate it with other mechanism. C++ directly supports exception handling, which makes life of developer easy.
3. What is an Object/Instance?
4. What do you mean by C++ access specifiers ?
Members declared as private are accessible only with in the same class and they cannot be accessed outside the class they are declared.
Members declared as public are accessible from any where.
Members declared as protected can not be accessed from outside the class except a child class. This access specifier has significance in the context of inheritance.
5. What are the basics concepts of OOP?
- Classes and Objects
- Data abstraction
6. What is the use of volatile keyword in c++? Give an example.
Volatile keyword is used to tell compiler that the variable declared using volatile may be used from outside the current scope so that compiler wont apply any optimization. This matters only in case of multi-threaded applications.
In the above example if variable ‘a’ was declared using volatile, compiler will not optimize it. In shot, value of the volatile variables will be read from the memory location directly.