C++

Here are some frequently asked question and answers on C++ programming language, the questions can help you to prepare for a job interview. Checkout now !!

Q.1 What is a namespace?
A namespace is useful for resolving the name conflict of the identifier. This can be accomplished by placing them under various namespaces. This is how it helps in the logical division of various codes.
Q.2 Can we call C++ OOPS?
Yes, we can call C++ an Object-Oriented Programming System(OOPS) that is a paradigm providing an application of different concepts, including data binding, inheritance, polymorphism and various others.
Q.3 Define storage class.
Storage class in C++ resembles life or the scope of symbols, consisting of the variables, functions, etc.
Q.4 When does function overloading happen?
Function overloading occurs in C++ when two or more functions share the same name. They can be separated on the basis of the type of data they are passing as parameters or the number of parameters they are passing.
Q.5 Define class in C++.
Class is the designing of the user-defined data type. It basically reflects various attributes, entities, and actions.
Q.6 What is a stream?
Stream represents a stream of characters that are to be transferred between program thread and i/o.
Q.7 What does inheritance in C++ refer to?
C++ enables classes to inherit some commonly used state and behaviour from other classes. This process is called inheritance.
Q.8 Define the term type casting.
Type casting is used for changing the data type. There are two types of type casting including implicit type conversion and explicit type conversion.
Q.9 What is an abstraction in C++?
An abstraction is hiding the internal implementations and displaying the required details only. For instance, while sending an important message via email, only writing and clicking the send option is used. This outcome is the success message that is displayed to confirm that your email has been sent. However, the process followed in transferring the data is not displayed because it is of no use.
Q.10 Name some storage classes in C++.
Some of the storage class names in C++ are mutable, static, register, auto, extern, etc.
Q.11 What is stl in C++?
Stl stands for standard template library. It is a library that lets us use a standard set of templates for things like algorithms, iterators, functions in place of actual code.
Q.12 What is an access specifier?
An access specifier provides how it is possible to define how the class members including functions and variables, will be accessed outside the scope of class.
Q.13 What is a string?
A string is actually a sequence of characters. In C++, it is a data type and a header file. This header file has powerful functions of string manipulation.
Q.14 What is an object in C++?
An object is an instance of the class. It can have methods, fields , constructors, and related.
Q.15 What is the function of the keyword: Volatile?
The keyword "Volatile" is a function helpful in declaring that a specific variable is volatile and hence direct the compiler to change the variable externally.
Q.16 How can we clear screen in C++?
We can clear screen in C++ by using – clrscr() or system(“clear”).
Q.17 What are the types of access specifiers?

The three types of access specifiers are:

  • Private
  • Protected
  • Public
Q.18 How many keywords are there in C++ ?
There are 95 reserved keywords in C++.
Q.19 Define a class template.
A class template is just a name that is given to the generic class. Keyword template is used for defining a class template.
Q.20 What does iostream in C++ refer to?
It is basically a header file that is inclusive of basic objects like cin, clog , cout and cerr.
Q.21 What do you mean by encapsulation?
Well, encapsulation is the process of binding the data and functions together in a class. It is used to prevent direct access to the data for security reasons. The functions of a class are applied for this purpose.
Q.22 What is method overloading?
Method overloading is the method which allows us to have more than one function with the same function name but with different functionality.
Q.23 Define Compile-time polymorphism.
Compile-time polymorphism is the polymorphism which is implemented at the compile time. An example of compile-time polymorphism is method overloading.
Q.24 On which basis is method overloading possible?
Method overloading can be possible on the basis of the return type of the overloaded function, the number of parameters passed to the function and the type of the parameters passed to the function.
Q.25 What is constructor C++?
A constructor in C++ is a 'MEMBER FUNCTION' that has the same name as the class that is used to initialize some valid values to the data members of an object.
Q.26 Mention the basic principles of OOP.

The basic principles of Object-Oriented-Programming are:

  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism
Q.27 How is C language different from C++?
The difference between the two is that C is a structured programming language and C++ supports both structural and object-oriented programming language. Moreover, C is a subset of C++.
Q.28 Define standard constructor.
The standard constructor is a constructor without arguments that is generated automatically by the compiler for all those classes that don't include any constructor definition. Moreover, the programmer can also define a constructor explicitly without arguments that replace the standard constructor.
Q.29 What are virtual functions?
Virtual functions are used with inheritance. They are called on the basis of the type of object pointed or referred and not according to the type of pointer or reference.
Q.30 What are primitive data types?
The primitive data types are built-in or predefined data types which can be directly used by the user to declare variables. For example char, int, float, bool etc.
Q.31 What are the necessary things to write a C++ program with runtime polymorphism?

1) A base class along with a derived class.

2) A pointer or reference of base class type pointing or referring to an object of the derived class.

3) A function with the same name in the base class and derived class.

Q.32 Name the primitive data types available in C++.

The primitive data types available in C++ are:

  • Integer
  • Character
  • Floating Point
  • Boolean
  • Valueless or Void Double
  • Floating Point
Q.33 What do you mean by datatype modifiers?
Datatype modifiers are used with the built-in data types for modifying the length of data that is held by a specific data type.
Q.34 What is wide character?
Wide character data type is a character data type having size greater than the normal 8-bit datatype. It is represented by wchar_t and is generally 2 or 4 bytes long.
Q.35 Define operator overloading.
Operator overloading is a necessary element for perform the operations on user-defined data types. Moreover, we can modify the default meaning to the operators by operator overloading.
Q.36 Name the data type modifiers available in C++.
The data type modifiers available in C++ are: Signed Unsigned Short Long
Q.37 What is an inline function?
For an inline function, the compiler places a copy of the code of that function at each point where the function is called at compile time. One of the advantages of using an inline function is that it removes the function calling overhead of a traditional function.
Q.38 What do you mean by reference in C++?
Reference is another name of an already existing variable. It is like a pointer. Once a reference name is initialized with a variable, that variable can be accessed by both the variable name or reference name.
Q.39 What is a destructor?
When an object is destroyed then the function called destructor automatically gets called. It has the same name as the constructor but is preceded by a tilde.
Q.40 Define a copy constructor.
A copy constructor is basically member function which is meant to initialize an object using another object of the same class.
Q.41 What are void pointers?
A void pointer is just a pointer having no datatype associated with it. Additionally, it can hold addresses of any type.
Q.42 What is a pure virtual function?
A pure virtual function is that function which has no implementation and is declared by assigning 0. It does not even have a body.
Q.43 What is a deep copy?
A deep copy makes a new and different copy of an entire object along with its unique memory address.
Q.44 What is an abstract class?
A class is known as an abstract class when its objects can never be created. Such type of class exists as a parent for the derived classes. Moreover, we can make a class abstract by placing a pure virtual function in the class.
Q.45 What is the purpose of protected access specifier?
In case a class member is protected then it is accessible in the inherited class. Therefore outside the both the private and protected members are not accessible.
Q.46 What do we do in call by value method?
In the call by value method, we generally pass a copy of the parameter to the functions. A new memory is assigned for these copied values. However, the changes made to these values do not reflect the variable in the main function.
Q.47 What is the purpose of the keyword volatile?
There is a process of declaring a variable volatile directs the compiler that the variable can be changed externally. Therefore avoiding compiler optimization on the variable reference.
Q.48 What are the types of polymorphism?
There are two types of polymorphism in C++ namely: 1.Compile Time Polymorphism 2.Runtime Polymorphism
Q.49 What is the primary role of static keyword on class member variable?
Indeed a static variable exit though the objects for the respective class are not created. Static member variable share a common memory across all the objects created for the respective class. A static member variable can be referred using the class name itself.
Q.50 What is a friend class?
A friend class is able to access private, protected, and public members of other classes wherein it is declared as friends.
Q.51 How do you define a destructor and how can it be overloaded?
A destructor is defined as the member function of the class having the same name as the class name and prefixed with tilde (~) symbol. Dtructor gets executed automatically with respect to the object as soon as the object loses its scope. It cannot be overloaded and the only form is without the parameters.
Q.52 Explain ‘this’ pointer.
The ‘this’ pointer is a constant pointer that holds the memory address of the current object. It passes as a hidden argument to all the nonstatic member function calls. Moreover, it is available as a local variable within the body of all the nonstatic functions.
Q.53 What is pointer?
Pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. Where ‘this’ pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name).
Q.54 What is the use of void main () in C++ language?
In order to run the C++ application it involves two steps,
The first step is a compilation where conversion of C++ code to object code take place.
The second step includes linking, where combining of object code from the programmer and from libraries takes place. Such that this function is operated by main () in C++ language.
Q.55 What are the characteristics of Class Members in C++?
Some of the characteristics of Class Members in C++ are -
1. Data and Functions are members in C++,
2. Within the class definition, data members and methods must be declared
3. Within a class, a member cannot be re-declare
4. Other that in the class definition, no member can be added elsewhere
Get Govt. Certified Take Test
 For Support