C++ programming is a general purpose programming language that was created by Bjarne Stroustrup. It is essential to know C++ if you want to work in the software development domain. C++ is an extension of C programming language.The blog will cover C++ Interview Questions for advanced levels, C++ programming interview questions, and more.
1. What is C++?
2. What are the advantages of C++?
- C++ is a highly portable language means that the software developed using C++ language can run on any platform.
- C++ is an object-oriented programming language which includes the concepts such as classes, objects, inheritance, polymorphism, abstraction.
- C++ has the concept of inheritance. Through inheritance, one can eliminate the redundant code and can reuse the existing classes.
- Data hiding helps the programmer to build secure programs so that the program cannot be attacked by the invaders.
- Message passing is a technique used for communication between the objects.
- C++ contains a rich function library.
3. What is the difference between C++ and Java?
The difference between c++ and java are as follows:
- C++ supports goto statements whereas Java does not.
- C++ is majorly used in system programming whereas Java is majorly used in application programming.
- C++ supports multiple inheritance whereas Java does not support multiple inheritance
- C++ supports operator overloading whereas Java does not support operator overloading.
- C++ has pointers which can be used in the program whereas Java has pointers but internally.
- C++ uses a compiler only whereas Java uses both compiler and interpreter.
- C++ has both call by value and call by reference whereas Java supports only call by value.
- C++ supports structures and joins whereas Java does not support structure and joins
- Java supports unsigned right shift operator (>>>) whereas C++ does not.
- C++ is interactive with hardware whereas Java is not that interactive with hardware.
4. What is the difference between C and C++?
C | C++ |
C language was developed by Dennis Ritchie. | C++ language was developed by Bjarne Stroustrup. |
C is a structured programming language. | C++ supports both structural and object-oriented programming language. |
C is a subset of C++. | C++ is a superset of C. |
In C language, data and functions are the free entities. | In the C++ language, both data and functions are encapsulated together in the form of a project. |
C does not support the data hiding. Therefore, the data can be used by the outside world. | C++ supports data hiding. Therefore, the data cannot be accessed by the outside world. |
C supports neither function nor operator overloading. | C++ supports both function and operator overloading. |
In C, the function cannot be implemented inside the structures. | In the C++, the function can be implemented inside the structures. |
Reference variables are not supported in C language. | C++ supports the reference variables. |
C language does not support the virtual and friend functions. | C++ supports both virtual and friend functions. |
5. What is namespace in C++?
If there are two or more functions with the same name defined in different libraries then how will the compiler know which one to refer to? Thus namespace came to picture. A namespace defines a scope and differentiates functions, classes, variables etc. with the same name available in different libraries. The namespace starts with the keyword “namespace”. The syntax for the same is as follows:
Syntax:
namespace namespace_name {
// code declarations
}
6. What is a class?
The class is a user-defined data type. The class is declared with the keyword class. The class contains the data members, and member functions whose access is defined by the three modifiers are private, public and protected. The class defines the type definition of the category of things. It defines a datatype, but it does not define the data it just specifies the structure of data.
7. Define namespace in C++?
- The namespace is a logical division of the code which is designed to stop the naming conflict.
- The namespace defines the scope where the identifiers such as variables, class, functions are declared.
- The main purpose of using namespace in C++ is to remove the ambiguity. Ambiquity occurs when the different task occurs with the same name.
- For example: if there are two functions exist with the same name such as add(). In order to prevent this ambiguity, the namespace is used. Functions are declared in different namespaces.
- C++ consists of a standard namespace, i.e., std which contains inbuilt classes and functions. So, by using the statement "using namespace std;" includes the namespace "std" in our program.
8. What are the different data types present in C++?
- Primitive Datatype(basic datatype). Example- char, short, int, float, long, double, bool, etc.
- Derived datatype. Example- array, pointer, etc.
- Enumeration. Example- enum
- User-defined data types. Example- structure, class, etc.
9.What is template in C++?
10.What are the various OOPs concepts in C++?
- Static polymorphism is also known as early binding.
- Dynamic polymorphism is also known as late binding.
11.What are the different types of polymorphism in C++?
- The return type of the overloaded function.
- The type of the parameters passed to the function.
12.Define token in C++?
13.Who was the creator of C++?
14. Which operations are permitted on pointers?
15. Define 'std'.
16. Which programming language's unsatisfactory performance led to the discovery of C++?
17. What are the C++ access specifiers?
18.How delete [] is different from delete?
19. What is the full form of STL in C++?
20. What is an object?
21. 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.
22. What is the difference between an array and a list?
23. What are the methods of exporting a function from a DLL?
- By using the DLL's type library.
- Taking a reference to the function from the DLL instance.
24. Define friend function?
- The friend function is not in the scope of the class in which it has been declared.
- Since it is not in the scope of the class, so it cannot be called by using the object of the class. Therefore, friend function can be invoked like a normal function.
- A friend function cannot access the private members directly, it has to use an object name and dot operator with each member name.
- Friend function uses objects as arguments
25. What is a virtual function?
- The virtual functions should be a member of some class.
- The virtual function cannot be a static member.
- Virtual functions are called by using the object pointer.
- It can be a friend of another class.
- C++ does not contain virtual constructors but can have a virtual destructor.
26.When should we use multiple inheritance?
- Never
- Rarely
- If you find that the problem domain cannot be accurately modeled any other way.
27. What is an overflow error?
28. What is a destructor?
- Destructors have the same name as class name and it is preceded by tilde.
- It does not contain any argument and no return type.
29. What is overloading?
- Member function
- Non-member function
- Friend function
30. What is function overriding?
31.What is a pure virtual function?
32. What is virtual inheritance?
33. What is the purpose of the "delete" operator?
34. What is a constructor?
35. Explain this pointer?
36. What does Scope Resolution operator do?
37. What is the difference between delete and delete[]?
38. What is the difference between struct and class?
Structures |
class |
A structure is a user-defined data type which contains variables of
dissimilar data types. |
The class is a user-defined data type which contains member variables and member functions. |
The variables of a structure are stored in the stack memory. |
The variables of a class are stored in the Heap memory. |
We cannot initialize the variables directly. |
We can initialize the member variables directly. |
If access specifier is not specified, then by default the access specifier of the variable is "public". |
If access specifier is not specified, then by Default the access specifier of
a variable is "private". |
A structure is declared by using a struct keyword. |
The class is declared by using a class keyword. |
The structure does not support the inheritance. |
The class supports the concept of inheritance. |
The type of a structure is a value type. |
The type of a class is a reference type. |
39. What is the difference between function overloading and operator overloading?
40. What is a class template?
41. What is a virtual destructor?
42. Compare compile time polymorphism and Runtime polymorphism?
The main
difference between compile-time and runtime polymorphism is provided below:
Compile-time
polymorphism |
Run
time polymorphism |
In this
method, we would come to know at compile time which method will be called.
And the call is resolved by the compiler. |
In this
method, we come to know at run time which method will be called. The call is
not resolved by the compiler. |
It provides
fast execution because it is known at the compile time. |
It provides
slow execution compared to compile-time polymorphism because it is known at
the run time. |
It is
achieved by function overloading and operator overloading. |
It can be
achieved by virtual functions and pointers. |
43.What do you know about friend class and friend function?
44. What are the C++ access specifiers?
45. Define inline function?
46. What do you mean by call by value and call by reference?
47. What is an abstract class and when do you use it?
48. Can we call a virtual function from a constructor?
49. What are void pointers?
50.What is this pointer in C++?
51. what is type casting in C++?
52. How to clear screen in C++?
53. Who developed C++?
54. How to compile and run C program in notepad++ ?
55. How many keywords in C++ ?
56. Which operator cannot be overloaded in C++ ?
- Dot operator- “.”
- Scope resolution operator- “::” .
- “sizeof” operator.
- Pointer to member operator- “.*” .
57. Why C++?
- It is used in developing graphic user interface based applications like adobe photoshop.
- It is used in developing games as it overrides the complexity of 3D games.
- There are many animated softwares developed in C++
- Most of the compilers are written in C++.
- Google Chrome, Mozilla Firefox etc. web browser are developed using C++
58. What is stack in C++?
- Push: adding element to stack.
- Pop: removing element from stack.
- isEmpty: returns true if stack is empty.
- Top: returns the top most element in stack.
59. What is exception in C++ ?
- try
- catch
- throw
60. What is :: in C++?
61. What is conio.h in C++?
62. What are the advantages of C++?
- Mid-level programming language.
- Portability.
- C++ has the concept of inheritance.
- Multi-paradigm programming language.
- Memory Management.
63. What is an expression in C++?
- Constant expressions: 89 +10/4.0 .
- Integral expressions: x * y.
- Floating expressions: 17.89.
- Relational expressions: a<=b.
- Logical expressions: a > b && a == 7.
- Pointer expressions: *ptr.
- Bitwise expressions: p << 5