C++ Interview Questions (JNNC Technologies)


C++ Interview Questions

A list of top frequently asked C++ interview questions and answers are given below.

1) What is C++?

C++ is an object oriented programming language created by Bjarne Stroustrup. It is released in 1985.

2) What are the advantages of C++?

C++ doesn't only maintains all aspects from C language, it also simplify memory management and add several features like:
  • Includes a new datatype known as a class.
  • Allows object oriented programming.

3) What is the difference between C and C++?

No.CC++
1)C follows the procedural style programming.C++ is multi-paradigm. It supports both procedural and object oriented.
2)Data is less secured in C.In C++, you can use modifiers for class members to make it inaccessible for outside users.
3)C follows the top-down approach.C++ follows the bottom-up approach.
4)C does not support function overloading.C++ supports function overloading.
5)In C, you can't use functions in structure.In C++, you can use functions in structure.
6)C does not support reference variables.C++ supports reference variables.
6)In C, scanf() and printf() are mainly used for input/output.C++ mainly uses stream cin and cout to perform input and output operations.

4) What is the difference between reference and pointer?

No.ReferencePointer
1)References are less powerful than pointers. Once a reference is created, it can't refer to other object later.Pointers provide the powerful facilities than references.
2)References are safer and easier to use than pointers.Pointers are comparatively difficult to use.

5) What is a class?

Class is a user-defined data type. Class defines the type definition of category of things. It defines a datatype, but it does not define the data it just specifies the structure of data.
You can create N number of objects from a class.

6) What is an object?

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.

7) 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.

8) 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 datatype. 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 hide the data from 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.

9) What is the difference between array and a list?

  • Array is a collection of homogeneous elements while 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 list user has to keep in track of next location where memory is allocated.

10) 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.

Post a Comment

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();