C++ Interview FAQ's
1.What is C++?
C++ is a high level, general purpose, object oriented programming language. C++ is a compiler based programming language.
2.What is a compiler?
A compiler is a translator software that converts a high level programming language like C++ from programmer entered English instructions or source code to machine readable Binary code or machine code.
3.What is Object Oriented Programming?
Object Oriented Programming is a type of programming where the objects control the type of actions taken by the program in a class. Objects define the different attributes of the language.
4.What is class?
Class in programming is the blueprint that structures and specifies how that portion of the program shall work. Class defines the data type, while objects in the class define the actions taken. There may be as many objects inside a class as required.
5.What is Encapsulation?
Encapsulation is the mechanism of C++ where data and its associated operations are bound together to form a shell (class), that limits accessibility of the data to the outside world. It is also called Data Hiding and is an important advantage of C++ language.
6.What is Inheritance?
Inheritance is the process where the properties and attributes of existing classes are made available to other classes in a program without the need to specify the details of the classes again and again. The existing classes are called base classes, and the classes newly created from them are called derived classes.
7.What is Abstraction?
Abstraction is another feature of C++ where the internal working of the program is hidden and only the necessary details are made visible.
8.What are the types of Inheritance in C++?
- Single Inheritance: Inheritance of one derived class from one base class.
- Multiple Inheritance: Inheritance of one class from more than one base classes.
- Multi level Inheritance: Inheritance of a class from another class which was further derived from another class.
- Hierarchical Inheritance: Inheritance of more than one class from a single base class.
- Hybrid Inheritance: Inheritance of classes using more than one inheritance type.
9.What is meant by storage class?
Storage class describes the scope, or lifetime of the symbols used in the program, like functions, variables, etc.
10.What are the types of storage classes used in C++?
Storage classes supported in C++ are static, register, extern, mutable, and auto.
11.What is a constructor?
A constructor is a member function of a class with the same name as the class name. The constructor function gets executed as soon as the object for that class is created.
12.What is a default constructor?
If the programmer does not specify a constructor, the compiler automatically provides a constructor for the class. If the programmer specifies a constructor function without any parameters, the compiler does not give a constructor. This is called a default constructor.
13.What is a destructor?
Destructor is the member function of a class with the same name as the class, with a tilde symbol (~) as prefix. Hence, it is a constructor with a ~ prefix. The destructor is executed when the object of the class ends its scope, or finishes its lifetime.
14.What is recursion?
Recursion is the phenomenon where a function calls itself in the program.
15.What is visibility mode of inheritance?
According to data hiding, data members of a class are not available outside unless one or more classes are inherited from it. Visibility mode determines which data members are available to the derived classes. There are three visibility modes of inheritance in C++: public, private, and protected.
16.What is public inheritance?
All data members declared under public in a class are available to the derived classes, and become public members of the derived classes.
17.What is private inheritance?
Data members declared under private in a class are not available to any function outside that class. If the inheritance mode is not declared in the program, it is defined by default as private.
18.What is protected inheritance?
Data members declared as protected in a class are available to functions in the directly derived class only, and they become protected members of the derived class.
19.What is a preprocessor?
Preprocessor is an instruction to the compiler to perform some tasks before actually starting compilation of the program.
20.What is a container class?
A Container Class is a class containing at least one member variable of another class type.
21.What is token?
A token can be a keyword, a constant, a symbol, string literal, or identifier. A C++ program is made up of different tokens.
22.What happens when a C++ program without a main () function is run?
A program without a main () function definition can be compiled, but it cannot be executed.
23.What is register storage specifier?
Variables declared under a register storage specifier are assigned CPU register memory for their storage. These variables require less time to be called and used by the functions. Hence, variables that are to be used repeatedly are declared under register storage specifier.
24.What is overloading?
Overloading is the phenomenon where more than one definition can be specified for some functions and objects within the same scope. They are then called function overriding, and object overloading respectively.
25.What is function overriding?
If the functions of a base class are defined again in the derived class, the phenomenon is called function overriding.
26.What are command line arguments?
Arguments or parameters sent to the main() function from the command line or console while the program is being executed is called command line arguments. All such arguments are sent as strings.