/TheCppProgrammingLanguage

The C++ compendium of knowledge based on "The C++ Programming Language Fourth Edition" by Bjarne Stroustrup

Primary LanguageC++

1. What is the difference between C and C++?

C C++
  • C language is a procedure
    oriented programming language
  • It follows top-down approach
  • It doesn't support function or
    operator overloading
  • C language doesn't support
    virtual and friend function
  • C language has 32 keywords
  • C++ is partially object oriented
    programming language
  • It follows bottom-up approach
  • It supports function as well as
    function overloading
  • C++ language supports both
    virtual and friend functions
  • C++ language has 52 keywords

2. What are classes and objects in C++?

A class is a user-defined datatype members and member functions and
is defined with the keyword class. Objects are defined as an instance of a class. Once the object is created,
then it can operate on both data members and member functions.

3. What are access modifiers?

Access modifiers are used to define accessibility for the class members.
It defines how the members of the class are accessed outside the class scope.
There are three types of access modifiers:

  • Private
  • Public
  • Protected

4. What are C++ OOPs concept?

  • Object
  • Class
  • Inheritance
  • Abstraction
  • Encapsulation
  • Polymorphism

5. What is an object in C++?

An object is an instance of a class with the class's own methods or procedures
and data variables.

6. What is class in C++?

A class is a user-defined data type that we can use in our program, and it works
as an object constructor, or a "blueprint" for creating objects.

7. What is the inheritance in C++?

Inheritance is one of the main features of object-oriented programming in C++,
allowing us to inherit another class's properties.

8. What is meant by abstraction in C++?

Data abstraction refers to providing only essential information to the outside
world and hiding their background details.

9. What is Encapsulation in C++?

Encapsulation is an Object Oriented Programming concept that binds together
the data and functions that manipulate the data, and that keeps both safe from
outside interference and misuse.

10. What is Polymorphism in C++?

What is Polymorphism in C++? Polymorphism in C++ means, the same entity
(function or object) behaves differently in different scenarios.

11. What is a Vector in STL?

Vectors are the same as dynamic arrays with the ability to resize itself automatically
when an element is inserted or deleted, with their storage being handled automatically
by the container.

12. What is a List in STL?

Lists are sequence containers that allow non-contiguous memory allocation.
As compared to vector, the list has slow traversal, but once a position has been
found, insertion and deletion are quick.

13. What is a Map in STL?

Maps are associative containers that store elements in a mapped fashion.
Each element has a key value and a mapped value. No two mapped values
can have the same key values.

14. What is a Constructor?

A constructor is a member function taht is invoked whenever we create an object,
it has the same name as that of the class.
There are 2 types of constructors:

  • Default constructor
  • Parameterized constructor

15. What is a Destructor?

A destructor is a member function that is invoked automatically when the object goes out
of scope or is explicitly destroyed by a call to delete.

16. What is operator overloading in C++?

It's a type of polymorphism in which an operator is overloaded to give it the user-defined
meaning. C++ allows us to specify more than one definition for a function name or an operator
in the same scope, which is called function overloading and operator overloading, respectively.

17. What is a pointer?

A pointer is a variable that stores the memory address of another variable as its value.
Pointers are used extensively in both C and C++ for three main purposes: to allocate new
objects on the heap, to pass functions to other functions. to iterate over elements in arrays
or other data structures.

18. What is a reference?

A reference variable is an alias, that is, another name for an already existing variable.
Once a reference is initialized with a variable, either the variable name or the reference
name may be used to refer to the variable.

19. What is the difference between reference and pointer?

References are used to refer an existing variable in another name whereas pointers
are used to store address of variable. References cannot have a null value assigned
but pointer can. A reference variable can be referenced by pass by value whereas a
pointer can be referenced by pass by reference.

20. What is an enum?

An enumeration, or Enum , is a symbolic name for a set of values. Enumerations are
treated as data types, and you can use them to create sets of constants for use with
variables and properties.

21. What is the difference between Vector and List?

Vector List
  • It has contiguous memory
  • It is synchronized
  • Vector may have a default size
  • In vector, each element only
    requires the space for itself only
  • Random access of elements is possible
  • It has non-contiguous memory
  • It is not synchronized
  • List does not have default size
  • In list, each element requires
    extra space for the node which holds
    the element, including pointers to the
    next and previous elements in the list.
  • Random access of elements is not possible

22. What is std::move?

std::move is used to indicate that an object t may be "moved from", i.e. allowing the efficient transfer
of resources from t to another object.

23. What is constexpr used for?

constexpr indicates that the value, or return value, is constant and, where possible, is computed at compile time.