The main objective of this post is to provide the main and important C++ questions, so that students can prepare them for their exams. Here are some important questions and i’ll update this post timeto time. At the end of this post you can download pdf.

  1. Name the operators that cannot be overloaded.

sizeof, ., .*, .->, ::, ?

  1. What is inheritance?

Inheritance is property such that a parent (or super) class passes the characteristics of itself to children (or sub) classes that are derived from it. The sub-class has the option of modifying these characteristics in order to make a different but fundamentally related class from the super-class.

  1. What are instance variables?

These represent an object’s private memory. They are defined in an object’s class.

  1. What is a super-class?

Given a class, a super-class is the basis of the class under consideration. The given class is defined as a subset (in some respects) of the super-class. Objects of the given class potentially posses all the characteristics belonging to objects of the super-class.

  1. What is an object in C++?

An object is a package that contains related data and instructions. The data relates to what the object represents, while the instructions define how this object relates to other objects and itself.

  1. What is polymorphism?

The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.

C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

  1. What is operator overloading?

It is the process of, and ability to redefine the way an object responds to a C++ operator symbol. This would be done in the object’s class definition.

  1. Define Copy Constructor.

A copy constructor is invoked when you initialize a new object of a class using an existing object. This will happen when:

  • You pass a copy of an object as argument to a function (i.e. when passing by value).
  • When you return an object from a function
  • Or initialize an object during declaration using another object.

If we don’t specify a copy constructor, the compiler already has a default copy constructor.

  1. What is the difference between overriding and overloading?

An overrided method redefines an existing method in a superclass to specify a new behavior. Overloading means that you have multiple methods with the same name but with a different parameter list.

  1. What is inline function?

When you call the function, execution of the program jumps to those instructions, and when the function returns, execution jumps back to the next statement in the calling function. Performance degradation occurs in jumping into and out of functions. When a function is small, the program can be speeded-up using inline functions. The use of inline functions avoids have the program jump into and out of the same function over and over again.If a function is declared with the keyword ‘inline’, the compiler does not create a real function; it copies the code from the inline function directly into the calling function. No jump is made.

  1. Write a short notes on recursion with example.

Recursion is defined as a function calling itself. It is in some ways similar to a loop because it repeats the same code, but it requires passing in the looping variable and being more careful. Many programming languages allow it because it can simplify some tasks, and it is often more elegant than a loop.

void recurse()

{

  recurse();

}

void main()

{

  recurse();

}

  1. Is it possible to accept command line argument in C++?

Yes, In C++ it is possible to accept command line arguments. To do so, you must first understand the full definition of int main(). It actually accepts two arguments, one is number of command line arguments, the other is a listing of the command line arguments.

Ex.

int main( int argc, char *argv[])

  1. Explain typecasting.

Typecasting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make ‘a’ function as a char.

  1. What’s the difference between public, private and protected?
  • A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class
  • A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes
  • A member (either data member or member function) declared in a public section of a class can be accessed by anyone
  1. What are some advantages/ disadvantages of using friend functions?

Member functions and friend functions are equally privileged. The major difference is that a friend function is called like f(x), while a member function is called like x.f(). Thus the ability to choose between member functions (x.f()) and friend functions (f(x)) allows a designer to select the syntax that is deemed most readable, which lowers maintenance costs. The major disadvantage of friend functions is that they require an extra line of code when you want dynamic binding.

  1. What’s the difference between the keywords struct and class in c++?

The members and base classes of a struct are public by default, while in class, they default to private.

  1. What is c++?

C++ is a general purpose object oriented programming language invented in the early 1980 by bajarne stroutrup.

  1. What is class?

A class can be declared as a collection of data members along with members function which allows association of data and functions into a single unit called encapsulation

  1. What are the different features of c++?

Following are the different features of the Classes in C++,

  • Operators and function overloading
  • Free storage management
  • Constant types
  • References
  • Inline function
  • Virtual function
  • Templates
  • Exception handling
  1. Explain constructor?

Constructors is a member function having the same name as that of its class and is executed automatically when the class is instantiated (object is created).

  1. What is a function?

A function is a block of code which executes the statements when we call it. It consists of three entities:

1) the function name. This is simply a unique identifier.

2) The function parameters. This is a set of zero or more typed identifier.

3) The function returns type this specifies the type of value function returns.

  1. Explain Inline function?

Inline functions are those functions whose function body is inserted in place of the function call.

  1. What is function overloading?

Function polymorphism for function overloading is a concept that allows multiple functions to share the same name with different arguments type assigning one or more function body to the same name is known as function overloading.

  1. What is implicit and explicit type conversion?

In implicit casting in c++ compile automatically handle the type conversion. The final result expressed in the highest precision possible. Explicit: the conversion of data type of two operands is not automatic but forced. We can force an expression to be a specific type by using a cast.

  1. What is inheritance in C++ and name the different types of inheritance?

It is a technique of organizing information in a hierarchy form. It is like a child inheriting the features of its parent. The class which we are inheriting from is called as the base class and the class which inherits called as derived class. Different types of inheritance are as follows-:

1) single level

2) Multi-level

3) Multiple

4) Hierarchical (hybrid)

5) multipath.

  1. What is friend function?

A friend function is a function which is use to access the private data member of different class.

 

Click here to download the C++ important questions with answers in pdf- c_plus_plus_important_question

Advertisements