Home / Interview / C++ :: General Questions

Interview :: C++

11) Define 'std'.

Std is the default namespace standard used in C++.

12) Which programming language's unsatisfactory performance led to the discovery of C++?

C++was discovered in order to cope with the disadvantages of C.

13) How delete [] is different from delete?

Delete is used to release a unit of memory, delete[] is used to release an array.

14) What is the full form of STL in C++?

STL stands for Standard Template Library.

15) What is an object?

The Object is the instance of a class. A class provides a blueprint for objects. So you can create an object from a class. The objects of a class are declared with the same sort of declaration that we declare variables of basic types.

16) What are the C++ access specifiers?

The access specifiers are used to define how to functions and variables can be accessed outside the class.

There are three types of access specifiers:

  • Private: Functions and variables declared as private can be accessed only within the same class, and they cannot be accessed outside the class they are declared.
  • Public: Functions and variables declared under public can be accessed from anywhere.
  • Protected: Functions and variables declared as protected cannot be accessed outside the class except a child class. This specifier is generally used in inheritance.
17) What is Object Oriented Programming (OOP)?

OOP is a methodology or paradigm that provides many concepts. The basic concepts of Object Oriented Programming are given below:

Classes and Objects: Classes are used to specify the structure of the data. They define the data type. You can create any number of objects from a class. Objects are the instances of classes.

Encapsulation: Encapsulation is a mechanism which binds the data and associated operations together and thus hides the data from the outside world. Encapsulation is also known as data hiding. In C++, It is achieved using the access specifiers, i.e., public, private and protected.

Abstraction: Abstraction is used to hide the internal implementations and show only the necessary details to the outer world. Data abstraction is implemented using interfaces and abstract classes in C++.

Some people confused about Encapsulation and abstraction, but they both are different.

Inheritance: Inheritance is used to inherit the property of one class into another class. It facilitates you to define one class in term of another class.

18) What is the difference between an array and a list?
  • An Array is a collection of homogeneous elements while a list is a collection of heterogeneous elements.
  • Array memory allocation is static and continuous while List memory allocation is dynamic and random.
  • In Array, users don't need to keep in track of next memory allocation while In the list, the user has to keep in track of next location where memory is allocated.
19) What is the difference between new() and malloc()?
  • new() is a preprocessor while malloc() is a function.
  • There is no need to allocate the memory while using "new" but in malloc() you have to use sizeof().
  • "new" initializes the new memory to 0 while malloc() gives random value in the newly allotted memory location.
  • The new() operator allocates the memory and calls the constructor for the object initialization and malloc() function allocates the memory but does not call the constructor for the object initialization.
  • The new() operator is faster than the malloc() function as operator is faster than the function.
20) What are the methods of exporting a function from a DLL?

There are two ways:

  • By using the DLL's type library.
  • Taking a reference to the function from the DLL instance.