{"id":21307,"date":"2023-11-08T10:10:59","date_gmt":"2023-11-08T04:40:59","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/"},"modified":"2025-01-22T15:31:53","modified_gmt":"2025-01-22T10:01:53","slug":"cpp-interview-questions","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/","title":{"rendered":"Top 100 C++ Interview Questions and Answers"},"content":{"rendered":"\n<p>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 the C programming language. The first set of c++ interview questions is curated for freshers and talks about the basic c++ interview questions.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p>Great Learning has curated a list of the top 20 frequently asked c++ interview questions; they are:<\/p>\n\n\n\n<p>This C++ interview questions blog is further divided into groups as follows.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basic C++ Interview Questions<\/li>\n\n\n\n<li>Advanced C++ Interview Questions<\/li>\n\n\n\n<li>C++ Programming Interview Questions<\/li>\n\n\n\n<li>C++ OOPS Interview Questions<\/li>\n\n\n\n<li>C++ Interview Questions FAQS<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-c-interview-questions\"><strong>Basic C++ Interview Questions<\/strong><\/h2>\n\n\n\n<p>All set to kickstart your coding career in c++?&nbsp; Look no further and start your professional career with these c++&nbsp;interview questions for freshers. We will start with the basics and slowly move towards slightly advanced questions to set the pace. If you are an experienced professional, this section will help you brush up on your C++ skills.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-c\"><strong>What is C++?<\/strong><\/h3>\n\n\n\n<p>As an extension of the C language, C++ was developed by Bjarne Stroustrup as a general-purpose cross-platform language which gives programmers a high level of control over system resources and memory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"why-c\"><strong>&nbsp;Why C++?<\/strong><\/h3>\n\n\n\n<p>The use of C++ is varied such as:<\/p>\n\n\n\n<p>- It is used in developing graphical user interface-based applications like adobe photoshop.<\/p>\n\n\n\n<p>- It is used in developing games as it overrides the complexity of 3D games.<\/p>\n\n\n\n<p>- There is much-animated software developed in C++<\/p>\n\n\n\n<p>- Most of the compilers are written in C++.<\/p>\n\n\n\n<p>- Google Chrome, Mozilla Firefox etc. web browsers are developed using C++<\/p>\n\n\n\n<p>There are many more such uses that make C++ the desired language.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/48ZmGDeE6BrftMsfGvltPTDWPzNoQbXjn4Wfccrwjxij8XuqM1vZItpPNpwPw8pVNQ345oLx52chNyTzFHe-xtqYtI2MwaOGqZ_wFi0xGzi_IOsIhe5lnblW19npcgy0jKGaLyvlJNtYyFFq00Xx1G7g-WED_khvrYELlyd0POPnCJcMgchNgVD6Vg\" alt=\"why c++?\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-namespace-in-c\"><strong>&nbsp;What is namespace in C++?<\/strong><\/h3>\n\n\n\n<p>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 the picture. A namespace defines the scope and differentiates functions, classes, variables etc. with the same name available in different libraries. The namespace starts with the keyword \u201cnamespace\u201d. The syntax for the same is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnamespace namespace_name {\n\n   \/\/ code declarations\n\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-operator-overloading-in-c\"><strong>&nbsp;What is operator overloading in C++?<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/operator-overloading-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\">Operator overloading in C++<\/a> is an overloaded declaration is declaration in the same scope of function or operator declared with the same name more than once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-learn-c\"><strong>How to learn C++?<\/strong><\/h3>\n\n\n\n<p>C++ is a programming language which is an extension of C. Thus, one should prefer to learn C first (it\u2019s not necessary). After learning C, then understand the basic difference between C and C++. Implement all the basic programs you learnt in C in C++ also. Then dive into the OOPs concept of C++. Do as much hands-on as possible to understand basic OOPs, and then dive into advanced-level OOPs. When all the basics are clear, build a small game to understand the structure and remain concepts if any. By following all these steps one can learn C++.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-the-difference-between-c-and-c\"><strong>&nbsp;What is the difference between C and C++?<\/strong><\/h3>\n\n\n\n<p>The difference between c and c++ is that C++ is an object-oriented language, which means that it has all the features of C as well as its own thing which is the concept of OOP. C++ has many functionalities of OOP that are missing from C such as encapsulation, abstraction, classes, objects, etc.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table class=\"has-pale-cyan-blue-background-color has-background\"><tbody><tr><td><strong>C<\/strong><\/td><td><strong>C++<\/strong><\/td><\/tr><tr><td>C is a procedure-oriented programming language.<\/td><td>C++ is an object-oriented programming language.<\/td><\/tr><tr><td>C does not support data hiding.<\/td><td>C++ supports data hiding.<\/td><\/tr><tr><td>C is a subset of C++<\/td><td>C++ is a superset of C.<\/td><\/tr><tr><td>C doest not support Function and operator overloading<\/td><td>C++ support Function and operator overloading<\/td><\/tr><tr><td>Functions can not be defined inside structures.<\/td><td>Functions can be defined inside structures.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-template-in-c\"><strong>&nbsp;What is a template in C++?<\/strong><\/h3>\n\n\n\n<p>A<a href=\"https:\/\/www.mygreatlearning.com\/blog\/templates-in-cpp\/\"> template in C++<\/a> is used to pass data types as parameters. These make it easier and simpler to use classes and functions.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>template &lt;typename T&gt;\n\n    int fun (T a,T b)\n\n                {\n\n                        return (a+b);\n\n                }\n\n                int main(){\n\n                        cout&lt;&lt;fun&lt;int&gt;(11,22);\n\n                }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-using-namespace-std-in-c\"><strong>&nbsp;What is using namespace std in C++?<\/strong><\/h3>\n\n\n\n<p>Using<a href=\"https:\/\/www.mygreatlearning.com\/blog\/namespaces-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\"> namespace std in C++<\/a> tells the compiler that you will be making use of the namespace called 'std'. The 'std' namespace contains all the features of the standard library. You need to put this statement at the start of all your C++ codes if you don't want to keep on writing std:: infront of every variable\/string or whatever standard library feature you are making use of, as it becomes tedious to do so.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-download-turbo-c-for-windows-10\"><strong>&nbsp;How to download turbo C++ for windows 10?<\/strong><\/h3>\n\n\n\n<p>To download turbo c++ follow the steps mentioned below:<\/p>\n\n\n\n<p>Step-1: Download turbo C++ from http:\/\/www.turboccom\/p\/download.html<\/p>\n\n\n\n<p>Step-2: Extract the Turbo.C.zip file.<\/p>\n\n\n\n<p>Step-3: Run setup.exe file.<\/p>\n\n\n\n<p>Step-4: Follow the instructions mentioned.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/qQ3x4bbhFSsgFpMlo8O9usklQGrJdC920syuE_JzX7aT6p3_zxQ5_ZxO_LFboV26H396kF1Iqo5JaryU7YrA5iDATqePLidbDc9gkFkltyuwRn2YNDUJ3yNzGPmJRBraESwwDUNRx4VQiQeDp_RPwOQ\" alt=\"\u00a0How to download turbo C++ for windows 10?\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-paste-in-turbo-c\"><strong>How to paste in turbo C++?<\/strong><\/h3>\n\n\n\n<p>Paste in turbo C++ can be done by two techniques:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Shift+Insert<\/li>\n\n\n\n<li>Open the file in notepad with .cpp extension. Make the changes and save it. After saving the file, you can open it from the Turbo C++ application file menu from where you stored the cpp file.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-pointer-in-c\"><strong>What is a pointer in C++?<\/strong><\/h3>\n\n\n\n<p>Pointers in C++ are a data type that store the memory address of another variable.<\/p>\n\n\n\n<p>For eg.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>char *str = \"Hi, How are you?\";\n\n                Here the pointer variable *str points to the string \"Hi, How are you?\"\n\n                or\n\n                int age;\n\n                int *int_value;\n\n                *int_value = &amp;age;\n\n                cout&lt;&lt;\"Enter your age please:\";\n\n                cin&gt;&gt;age;\n\n                cout&lt;&lt;\"n Your age is:\"&lt;&lt;*int_value;\n\n                \/\/ this will print your age as the variable is pointing to the variable age.<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-function-in-c\"><strong>What is a function in C++?<\/strong><\/h3>\n\n\n\n<p>A function in C++ is a block of code that can be referenced from anywhere in the system and that serves a specific purpose.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int fun(){\n\n                int a = 11;\n\n                return 11;\n\n        }\n\n        int main(){\n\n                int b = fun();\n\n        }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-destructor-in-c\"><strong>What is a destructor in C++?<\/strong><\/h3>\n\n\n\n<p>Destructors in c++ are special functions\/methods that are used to remove memory allocation for objects. They are called usually when the scope of an object ends. eg. when a function ends you can call it a destructor. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nThey are of the same name as the class - syntax - ~&amp;lt;classname&gt;();\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-function-overloading-in-c\"><strong>What is function overloading in C++?<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\">Function Overloading<\/a> happens in C++ when two or more functions share the same name. They can be differentiated on the basis of the type of data they are passing as parameters or even the number of parameters they are passing. eg. int fun(char a); &amp; int fun(int b); &amp; void fun(int a, int b)<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-stl-in-c\"><strong>What is stl in C++?<\/strong><\/h3>\n\n\n\n<p>Stl is the standard template library. It is a library that allows you to use a standard set of templates for things such as: Algorithms, functions, Iterators in place of actual code.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>queue&lt;int&gt; Q;\n\n        for(k=0;k&lt;10;k++)\n\n        {\n\n                Q.push(k);\n\n        }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-run-a-c-program-in-cmd\"><strong>How to run a C++ program in cmd?<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">verify gcc installtion using the command:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n$ gcc -vthen go to your working directory or folder where your code is:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n$ cd &lt;folder_name&gt;then build the file containing your c code as such:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n$ gcc main.cpp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n\nor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n$ g++ -o main main.cpp&nbsp;then run the executable generated in your system:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n$ main.exe<\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-type-casting-in-c\"><strong>What is type casting in C++?<\/strong><\/h3>\n\n\n\n<p>Type casting in C is used to change the data type. They are of two types: Implicit Type Conversion: It is automatic. Explicit Type Conversion: It is user-defined.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-use-a-string-in-c\"><strong>How to use a string in C++?<\/strong><\/h3>\n\n\n\n<p>A string is a sequence of characters. In C++, the string is a data type as well as a header file. This header file consists of powerful functions of string manipulation. A variable of string is declared as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>string str= \"Hello\"; \n\nAnd to use string one needs to include the header file.\n\n\/\/ Include the string library\n\n#include &lt;string&gt;\n\n\/\/ Create a string variable\n\nstring str= \"Hello\";<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-stream-in-c\"><strong>What is stream in C++?<\/strong><\/h3>\n\n\n\n<p>Stream refers to a stream of characters to be transferred between program thread and i\/o.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-the-difference-between-structure-and-class-in-c\"><strong>What is the difference between structure and class in C++?<\/strong><\/h3>\n\n\n\n<p>The difference between structure and class is as follows:<\/p>\n\n\n\n<p>- By default, the data members of the class are private whereas data members of structure are public.<\/p>\n\n\n\n<p>- While implementing inheritance, the access specifier for struct is public whereas for class its private.<\/p>\n\n\n\n<p>- Structures do not have data hiding features whereas class does.<\/p>\n\n\n\n<p>- Structures contain only data members whereas class contains data members as well as member functions.<\/p>\n\n\n\n<p>- In structure, data members are not initialized with a value whereas in class, data members can be initialised.<\/p>\n\n\n\n<p>- Structures are stored as stack in memory whereas class is stored as heap in memory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-clear-screen-in-c\"><strong>How to clear screen in C++?<\/strong><\/h3>\n\n\n\n<p>One can clear screen using - clrscr() or system(\"clear\").<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-compile-and-run-c-program-in-notepad\"><strong>How to compile and run C program in notepad++ ?<\/strong><\/h3>\n\n\n\n<p>To compile and run c program in notepad++ follow the steps mentioned below:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>Step-1: Download and install notepad++\n\nStep-2: Download and install MinGw gcc along with gcc.\n\nStep-3: Configure notepad++ for gcc. This step can be further divided into two sub-steps. A: Create C compiler tool in Notepad++\n\nB: Creating C execution tool.\n\nStep-4: Execute C program in Notepad++<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-many-keywords-in-c\"><strong>How many keywords in C++?<\/strong><\/h3>\n\n\n\n<p>There are 95 reserved keywords in C++ which are not available for re-definition or overloading.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-iostream-in-c\"><strong>What is iostream in C++?<\/strong><\/h3>\n\n\n\n<p>It is a header file that includes basic objects such as cin, cout, cerr, clog.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-give-space-in-c\"><strong>How to give space in C++?<\/strong><\/h3>\n\n\n\n<p>In C++ programming, the space can be given using the following code.<\/p>\n\n\n\n<p>cout &lt;&lt; \" \" ;<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"which-operator-cannot-be-overloaded-in-c\"><strong>Which operator cannot be overloaded in C++ ?<\/strong><\/h3>\n\n\n\n<p>Some of the operators that cannot be overloaded are as follows:<\/p>\n\n\n\n<p>- Dot operator- \u201c.\u201d<\/p>\n\n\n\n<p>- Scope resolution operator- \u201c::\u201d<\/p>\n\n\n\n<p>- \u201csizeof\u201d operator<\/p>\n\n\n\n<p>- Pointer to member operator- \u201c.*\u201d<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-copy-and-paste-in-turbo-c\"><strong>How to copy and paste in turbo C++ ?<\/strong><\/h3>\n\n\n\n<p>Press Ctrl + Insert to copy.<\/p>\n\n\n\n<p>Press Shift + Insert to paste.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-an-exception-in-c\"><strong>What is an exception in C++?<\/strong><\/h3>\n\n\n\n<p>Runtime abnormal conditions that occur in the program are called exceptions. These are of 2 types:<\/p>\n\n\n\n<p>- Synchronous<\/p>\n\n\n\n<p>- Asynchronous<\/p>\n\n\n\n<p>C++ has 3 specific keywords for handling these exceptions:<\/p>\n\n\n\n<p>- try<\/p>\n\n\n\n<p>- catch<\/p>\n\n\n\n<p>- throw<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-the-difference-between-c-and-java\"><strong>What is the difference between C++ and Java?<\/strong><\/h3>\n\n\n\n<p>This is one of the most common c++ interview questions asked, the difference between c++ and java are as follows:<\/p>\n\n\n\n<p>- C++ supports goto statements whereas Java does not.<\/p>\n\n\n\n<p>- C++ is majorly used in system programming whereas Java is majorly used in application programming.<\/p>\n\n\n\n<p>- C++ supports multiple inheritance whereas Java does not support multiple inheritance<\/p>\n\n\n\n<p>- C++ supports operator overloading whereas Java does not support operator overloading.<\/p>\n\n\n\n<p>- C++ has pointers which can be used in the program whereas Java has pointers but internally.<\/p>\n\n\n\n<p>- C++ uses a compiler only whereas Java uses both compiler and interpreter.<\/p>\n\n\n\n<p>- C++ has both call by value and call by reference whereas Java supports only call by value.<\/p>\n\n\n\n<p>- C++ supports structures and joins whereas Java does not support structure and joins<\/p>\n\n\n\n<p>- Java supports unsigned right shift operator (&gt;&gt;&gt;) whereas C++ does not.<\/p>\n\n\n\n<p>- C++ is interactive with hardware whereas Java is not that interactive with hardware.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-stack-in-c\"><strong>What is stack in C++?<\/strong><\/h3>\n\n\n\n<p>A linear data structure which implements all the operations (push, pop) in LIFO (Last In First Out) order. Stack can be implemented using either arrays or linked list.The operations in Stack are<\/p>\n\n\n\n<p>- Push: adding element to stack<\/p>\n\n\n\n<p>- Pop: removing element from stack<\/p>\n\n\n\n<p>- isEmpty: returns true if stack is empty<\/p>\n\n\n\n<p>- Top: returns the top most element in stack<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-conio-h-in-c\"><strong>What is conio.h in C++?<\/strong><\/h3>\n\n\n\n<p>Conio.h is a header file used for console input and output operations and is used for creating text based user interfaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-exit-from-turbo-c\"><strong>How to exit from turbo C++?<\/strong><\/h3>\n\n\n\n<p>To exit Turbo C++, use the Quit option under the File Menu, or press Alt + X.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-iterator-in-c\"><strong>What is iterator in C++?<\/strong><\/h3>\n\n\n\n<p>Any object which has an ability to iterate through elements of the range it has been pointing to is called iterator.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-in-c\"><strong>What is :: in C++?<\/strong><\/h3>\n\n\n\n<p>:: is called a scope resolution operator which is used to access global variables with the same name as of local variables, for defining functions outside the class, for accessing static variables, and for referring to a class inside of another class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-enum-in-c\"><strong>What is enum in C++?<\/strong><\/h3>\n\n\n\n<p>enum is abbreviation of Enumeration which assigns names to integer constant to make a program easy to read. Syntax for the same:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nenum enum_name{const1, const2, ....... };\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-endl-in-c\"><strong>What is endl in C++?<\/strong><\/h3>\n\n\n\n<p>Endl is a predefined object of ostream class to insert a new line characters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-save-a-file-in-c\"><strong>How to save a file in C++?<\/strong><\/h3>\n\n\n\n<p>When you have written code in the file (notepad),save the file as \"hello.cpp.\" If you want to write in a file using C++ code, you can do it using iostream and fstream libraries in C++.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\n\n#include &lt;fstream&gt;\n\nusing namespace std;\n\nint main () {\n\n  ofstream file_name;\n\n  file_name.open (\"sample.txt\");\n\n  file_name&lt;&lt; \"Write in the file\";\n\n  file_name.close();\n\n  return 0;\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"which-operators-can-be-overloaded-in-c\"><strong>Which operators can be overloaded in C++?<\/strong><\/h3>\n\n\n\n<p>List of operators that can be overloaded are:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">+ , - , * , \/ , % , ^, &amp; , | , ~ , !, =, ++ , --, ==, != , &amp;&amp; , ||\n\n+= , -= , \/= , %= , ^= , &amp;=, |= , *= , = , [] , (), -&gt;, -&gt;* , new , new [] , delete , delete []<\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-include-all-libraries-in-c\"><strong>How to include all libraries in C++?<\/strong><\/h3>\n\n\n\n<p>The library &lt;bits\/stdc++.h&gt; in c++ is used to include all the libraries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-maximize-turbo-c-window\"><strong>How to maximize turbo C++ window?<\/strong><\/h3>\n\n\n\n<p>Alt+Enter is the keyboard shortcut used to maximize (full screen) turbo C++.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-an-expression-in-c\"><strong>What is an expression in C++?<\/strong><\/h3>\n\n\n\n<p>An expression is a combination of operators, constants and variables. These seven types of expressions for examples:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">- Constant expressions: 89 +10\/0\n\n- Integral expressions: x * y\n\n- Floating expressions: 189\n\n- Relational expressions: a&lt;=b\n\n- Logical expressions: a &gt; b &amp;&amp; a == 7\n\n- Pointer expressions: *ptr\n\n- Bitwise expressions: p &lt;&lt; 5<\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"why-namespace-std-is-used-in-c\"><strong>&nbsp;Why namespace std is used in C++?<\/strong><\/h3>\n\n\n\n<p>If the program does not have using namespace std; then when you write cout &lt;&lt;; you would have to put std::cout &lt;&lt;; same for other functions such as cin, endl etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"which-is-the-best-c-compiler\"><strong>Which is the best C++ compiler?<\/strong><\/h3>\n\n\n\n<p>There are several good compilers for C++ such as:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">MinGW \/ \nGCC- Borland c++\nDev C++\nEmbracadero\nClang \nVisual C++\nIntel C++\nCode Block<\/pre>\n\n\n\n<p>GCC and clang are great compilers if the programmers target more portability with good speed.<\/p>\n\n\n\n<p>Intel and other compilers target speed with relatively less emphasis on portability.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-are-the-different-data-types-present-in-c\"><strong>&nbsp;What are the different data types present in C++?<\/strong><\/h3>\n\n\n\n<p>The 4 data types in C++ are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Primitive Datatype such as char, short, int, float, long, double, bool, etc.<\/li>\n\n\n\n<li>Derived datatype such as an array, pointer, etc.<\/li>\n\n\n\n<li>Enumeration such as enum<\/li>\n\n\n\n<li>User-defined data types such as structure, class, etc.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-are-the-advantages-of-c\"><strong>&nbsp;What are the advantages of C++?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Mid-level programming language<\/li>\n\n\n\n<li>Portability<\/li>\n\n\n\n<li>C++ has the concept of inheritance<\/li>\n\n\n\n<li>Multi-paradigm programming language<\/li>\n\n\n\n<li>Memory Management<\/li>\n\n\n\n<li>C++ is a highly portable language<\/li>\n\n\n\n<li>Fast and Powerful<\/li>\n\n\n\n<li>C++ contains a rich function library<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-the-difference-between-reference-and-pointer\"><strong>&nbsp;What is the difference between reference and pointer?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table class=\"has-pale-cyan-blue-background-color has-background\"><tbody><tr><td><strong>Reference<\/strong><\/td><td><strong>Pointers<\/strong><\/td><\/tr><tr><td>Reference is used to refer to an existing variable in another name<\/td><td>Pointers are used to store the address of a variable<\/td><\/tr><tr><td>References cannot have a null value assigned<\/td><td>The pointer can have a null value assigned<\/td><\/tr><tr><td>A reference variable can be referenced bypassing by the value<\/td><td>The pointer can be referenced but passed by reference<\/td><\/tr><tr><td>A reference must be initialized on the declaration<\/td><td>Pointers no need to be initialized on the declaration<\/td><\/tr><tr><td>A reference shares the same memory address with the original variable and takes up some space on the stack<\/td><td>Pointer has its own memory address and size on the stack<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-exception-handling-in-c\"><strong>What is exception handling in C++?<\/strong><\/h3>\n\n\n\n<p>Exceptions are errors that happen during the execution of code. To handle them we use throw, try &amp; catch keywords.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-visual-c\"><strong>What is visual C++?<\/strong><\/h3>\n\n\n\n<p>C++ is a standardized language and Visual C++ is a product that implements the standard of C++. One can write portable C++ programs using Visual C++, but one can also use Microsoft-only extensions which destroy portability but enhances your productivity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-stl-in-c-with-example\"><strong>What is stl in C++ with example?<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/standard-template-library-in-c\/\" target=\"_blank\" rel=\"noreferrer noopener\">STL in C++<\/a> is a library and abbreviation of Standard Template Library. STL is a generalized library that provides common programming data structures\/ container classes, functions, algorithms, and iterators. STL has four components<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">- Algorithms: Searching and sorting algorithms such as binary search, merge sort etc.\n\n- Containers: Vector, list, queue, arrays, map etc.\n\n- Functions: They are objects that act like functions.\n\n- Iterators: It is an object that allows transversing through elements of a container, e.g., vector&lt;int&gt;::iterator.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-flush-in-c\"><strong>What is flush in C++?<\/strong><\/h3>\n\n\n\n<p>std::flush synchronizes the stream buffer with its controlled output sequence.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advanced-c-interview-questions\"><strong>Advanced C++ Interview Questions<\/strong><\/h2>\n\n\n\n<p>This section of the blog talks about advanced C++ Interview Questions for your reference.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-class-in-c\"><strong>What is a class in C++?<\/strong><\/h3>\n\n\n\n<p>C language is not an object-oriented programming language, so it is a constant attempt of C++ to introduce OOPs. Class is a user-defined data type that defines a blueprint of data type. For example,<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>class Circle{ \n\npublic:  \n\n float radius; \n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-inline-function-in-c\"><strong>What is inline function in C++?<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/inline-functions-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\">Inline functions<\/a> are functions used to increase the execution time of a program. Basically, if a function is inline, the compiler puts the function code wherever the function is used during compile time. The syntax for the same is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ninline return_type function_name(argument list) { \n\n   \/\/block of code \n\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-friend-function-in-c\"><strong>What is friend function in C++?<\/strong><\/h3>\n\n\n\n<p>A friend function has access rights to all private and protected members of the class.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>class Circle\n{&nbsp;&nbsp;&nbsp;\ndouble radius;&nbsp;&nbsp;&nbsp;\npublic:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\nfriend void printradius( Circle c );&nbsp;&nbsp;\n};\nvoid printradius(Circle c ) \n{&nbsp;&nbsp;&nbsp;\n\/* Because printradius() is a friend of Circle, it can&nbsp;&nbsp;&nbsp;directly access any member of this class *\/&nbsp;&nbsp;&nbsp;\ncout &lt;&lt; \"Radius of circle: \" \n&lt;&lt; c.width;}int main() \n{&nbsp;&nbsp;&nbsp;\nCircle c;&nbsp;&nbsp;&nbsp;\n\/\/ Use friend function to print the radius.&nbsp;&nbsp;&nbsp;\nprintradius( c);&nbsp;&nbsp;&nbsp;return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-use-vector-in-c\"><strong>&nbsp;How to use vector in C++?<\/strong><\/h3>\n\n\n\n<p>A sample code to see how to use<a href=\"https:\/\/www.mygreatlearning.com\/blog\/vectors-in-c\/\" target=\"_blank\" rel=\"noreferrer noopener\"> vector in C++<\/a> is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include&lt;iostream&gt;  \n\n#include&lt;vector&gt;  \n\nusing namespace std;  \n\nint main()  \n\n{  \n\nvector &lt;string&gt; vec_1;  \n\nvec_push_back(\"sample code\");  \n\nvec_push_back(\"change example\");  \n\nfor(vector &lt;string&gt;::iterator i=vec_begin();i!=vec_end();++i)  \n\ncout&lt;&lt;*i;  \n\nreturn 0;   \n\n} <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-vector-in-c\"><strong>What is vector in C++?<\/strong><\/h3>\n\n\n\n<p>A sequence of containers to store elements, a vector is a template class of C++. Vectors are used when managing ever-changing data elements. The syntax of creating vector.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvector &amp;lt;type&gt; variable (number of elements)\n\nFor example:\n\nvector &amp;lt;int&gt; rooms (9);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-scope-resolution-operator-in-c\"><strong>What is scope resolution operator in C++?<\/strong><\/h3>\n\n\n\n<p>Scope resolution operator in c++ is denoted by double colon (::). It can be used:<\/p>\n\n\n\n<p>- when there is a local variable with same name as of global variable<\/p>\n\n\n\n<p>- When a function has to be defined outside a class<\/p>\n\n\n\n<p>- When class\u2019s static variables needs to be accessed<\/p>\n\n\n\n<p>- When a class inside another class has to be referred<\/p>\n\n\n\n<p>- In case of multiple Inheritance<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-are-character-constants-in-c\"><strong>What are character constants in C++?<\/strong><\/h3>\n\n\n\n<p>A character constant is member of the character set in which a program is written which is surrounded by single quotation marks (\u2018).<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-are-templates-in-c\"><strong>What are templates in C++?<\/strong><\/h3>\n\n\n\n<p>A feature that allows functions and classes to operate with generic types which means a function or class can work on different data types without being rewritten is called a template.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-sort-vector-in-c\"><strong>How to sort vector in C++?<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;bits\/stdc++.h&gt; \n\nusing namespace std; \n\nint main() \n\n{ \n\n    vector&lt;int&gt; vec{ 1,9,4,3,2,8,5,7}; \n\n    sort(vec.begin(), vec.end()); \n\n    for (auto x : v) \n\n        cout &lt;&lt; x &lt;&lt; \"\" \"\"; \n\n    return 0; \n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-pure-virtual-function-in-c\"><strong>What is pure virtual function in C++?<\/strong><\/h3>\n\n\n\n<p>A pure virtual function is a type of virtual function which does not have implementation, but is only declared. It is declared by assigning 0 in declaration.<\/p>\n\n\n\n<p>Syntax for the same is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Test \n\n{    \n\n    \/\/ Data members of class \n\npublic: \n\n    virtual void show() = 0; \n\n   \/* Other members *\/\n\n};\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-use-map-in-c\"><strong>How to use map in C++?<\/strong><\/h3>\n\n\n\n<p>Associative containers storing a combination of a key value or mapped value is called Maps. Syntax: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmap&amp;lt;key_type , value_type&gt; map_name;\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt; \n\n#include &lt;iterator&gt; \n\n#include &lt;map&gt; \n\nusing namespace std; \n\nint main() \n\n{\n\n    map&lt;int, int&gt; test; \n\n    \/\/ inserting elements \n\n    test.insert(pair&lt;int, int&gt;(1, 2)); \n\n    test.insert(pair&lt;int, int&gt;(2, 3)); \n\n    map&lt;int, int&gt;::iterator itr; \n\n    for (itr = test.begin(); itr != test.end(); ++itr) { \n\n        cout &lt;&lt; itr-&gt;first \n\n        cout &lt;&lt; itr-&gt;second &lt;&lt; 'n'; \n\n    } \n\n return 0;\n\n)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-empty-a-vector-in-c\"><strong>How to empty a vector in C++?<\/strong><\/h3>\n\n\n\n<p>Std::vector::empty tests whether a vector is empty or not. A sample code for illustrating the same is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\n\n#include &lt;vector&gt;\n\nint main ()\n\n{\n\n  std::vector&lt;int&gt; vec;\n\n  int add (0);\n\n  for (int i=1;i&lt;=5;i++) vec.push_back(i);\n\n  while (!vec.empty())\n\n  {\n\n     add+= vec.back();\n\n     vec.pop_back();\n\n  }\n\n  std::cout &lt;&lt; add;\n\n  return 0;\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-remove-segmentation-fault-in-c\"><strong>How to remove segmentation fault in C++?<\/strong><\/h3>\n\n\n\n<p>Segmentation fault indicates an error memory corruption. In layman terms, when a piece of code tries to do read and write operation in a read only location in memory. Below are the reasons and solutions for segmentation error:<\/p>\n\n\n\n<p>Reason: Accessing an address that is freed&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int* p = malloc(8); \n\n*p = 100; \n\n free(p);       \n\n *p = 110; <\/code><\/pre>\n\n\n\n<p>Solution: Before freeing the pointer check the assignment or any operation required to perform.<\/p>\n\n\n\n<p>Reason: Accessing out of array index bounds<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int arr&#091;2]; \n\narr&#091;3] = 10;  <\/code><\/pre>\n\n\n\n<p>Solution: Correcting the array bound<\/p>\n\n\n\n<p>Reason: Improper use of scanf()<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int n = 2; \n\nscanf(\"%d\",n); <\/code><\/pre>\n\n\n\n<p>Solution: To avoid this is the only solution<\/p>\n\n\n\n<p>Reason: Dereferencing uninitialized pointer<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int *p; \n\nprintf(\"%d\",*p);<\/code><\/pre>\n\n\n\n<p>Solution: A pointer must point to valid memory before accessing it.<\/p>\n\n\n\n<p>Reason: Stack Overflow<\/p>\n\n\n\n<p>Solution: It can be resolved by having a base condition to return from the recursive function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-initialize-a-2d-vector-in-c\"><strong>How to initialize a 2d vector in C++?<\/strong><\/h3>\n\n\n\n<p>The syntax to initialize a 2d vector is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstd::vector&amp;lt;std::vector&amp;lt;int&gt; &gt; name_of_vector;\n\nFor example: std::vector&amp;lt;std::vector&amp;lt;int&gt; &gt; v { { 1, 2, 1 },\n\n{ 2, 6, 7 } };\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"c-oops-interview-questions\"><strong>C++ OOPS Interview Questions&nbsp;<\/strong><\/h2>\n\n\n\n<p>C++ Interview Questions also include questions on OOPs Concepts. This section on C++ OOPS Interview Questions will help you learn more about the concepts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-oops-in-c\"><strong>What is oops in C++?<\/strong><\/h3>\n\n\n\n<p>OOP or Object Oriented Programming in C++ is a type of programming in which you create objects and classes to emulate real-world concepts such as Abstraction, Polymorphism, Encapsulation, and Inheritance.<\/p>\n\n\n\n<p>Here classes are data types that allow you to list several <a href=\"https:\/\/www.mygreatlearning.com\/blog\/types-of-data\/\" target=\"_blank\" rel=\"noreferrer noopener\">types of data<\/a> within it and even functions. You can access these classes with the help of class objects<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-constructor-in-c\"><strong>What is a constructor in C++?<\/strong><\/h3>\n\n\n\n<p>Constructor in C++ is a method in the class which has the same name as that of the class and is followed by parentheses (). It is automatically called when an object of a class is created.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>class Hello {     \/\/ The class\n\n  public:           \/\/ Access specifier\n\n    Hello() {     \/\/ Constructor\n\n      cout &lt;&lt; \"\"Hello World!\"\";\n\n    }\n\n};\n\nint main() {\n\n  Hello obj;    \/\/ Create an object of Hello (this will call the constructor)\n\n  return 0;\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-inheritance-in-c\"><strong>What is inheritance in C++?<\/strong><\/h3>\n\n\n\n<p>Inheritance in C++ is just like a child inherits some features and attributes from his parent similarly a class inherit attributes and methods from another class. The parent class is called base class and the child class is called derived class.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>\/\/ Base class\n\nclass Food_Item{\n\n  public:\n\n    void taste() { \n\n    cout &lt;&lt; \"\"The taste of every food item is different. n\"\" ;\n\n  }\n\n};\n\n\/\/ Derived class\n\nclass Chips: public Food_Item{\n\n  public:\n\n    void taste() {\n\n    cout &lt;&lt; \"\"The taste of chips is salty n\"\" ;   }\n\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-object-in-c\"><strong>What is object in C++?<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/\" target=\"_blank\" rel=\"noreferrer noopener\">Class in C++<\/a> provides a blueprint for object, that means, object is created from the class.<\/p>\n\n\n\n<p>For example,&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>class Circle{\n\npublic: \n\n        float radius;\n\n}\n\nCircle C1;\n\nCircle C2;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-encapsulation-in-c\"><strong>What is encapsulation in C++?<\/strong><\/h3>\n\n\n\n<p>To prevent access to data directly, Encapsulation is the process that combines data variables and functions in a class. This is achieved by doing the following:<\/p>\n\n\n\n<p>&nbsp;Making all data variables private.<\/p>\n\n\n\n<p>&nbsp;Creating getter and setter functions for data variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-an-abstraction-in-c\"><strong>What is an abstraction in C++?<\/strong><\/h3>\n\n\n\n<p>Abstraction in C++ means showing only what is necessary. It's part of the Object-oriented Programming concept. Abstraction is used to hide any irrelevant data from the outside world and only show what is absolutely necessary for the outside world to use.<\/p>\n\n\n\n<p>eg. Classes use the abstraction concept to only show relevant data types or elements. This is done through access specifiers such as: public, private, and protected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-member-function-in-c\"><strong>What is a member function in C++?<\/strong><\/h3>\n\n\n\n<p>Member functions are those functions that you declare within a class, they are members of the class. You can reference them using class objects. Eg:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>class A\n\n{\n\npublic:\n\n      int add(int b)\n\n      {\n\n      a = b * 10;\n\n      return a;\n\n      };\n\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-a-virtual-base-class-in-c\"><strong>What is a virtual base class in C++?<\/strong><\/h3>\n\n\n\n<p>Let's understand this with an example.<\/p>\n\n\n\n<p>You Have 4 classes: W,X,Y,Z<\/p>\n\n\n\n<p>Here X &amp; Y inherit from W. So they both have similar features being inherited from W.<\/p>\n\n\n\n<p>Now, Z inherits from both X &amp; Y<\/p>\n\n\n\n<p>Here Z may inherit similar features from X &amp; Y as they both have inherited them from W. This can cause issues and that's why we use virtual base classes as they stop multiple features of a class from appearing in another class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-access-private-members-of-a-class-in-c\"><strong>How to access private members of a class in C++?<\/strong><\/h3>\n\n\n\n<p>Private members of the class are not accessible by object or function outside the class. Only functions inside the class can access them or friend functions. However, pointers can be used to access private data members outside the class.<\/p>\n\n\n\n<p>The sample code is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt; \n\nusing namespace std; \n\nclass sample_test{ \n\nprivate: \n\n    int n; \n\npublic: \n\n    sample_test() { n = 45; } \n\n    int display() { \n\nreturn n; \n\n     } \n\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-call-a-base-class-constructor-from-a-derived-class-in-c\"><strong>How to call a base class constructor from a derived class in C++?<\/strong><\/h3>\n\n\n\n<p>A base class constructor will be called whenever the derived class constructor is called. Upon the creation of a derived class object, the order of constructor execution is: base class constructor then Default class constructor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-an-abstract-class-in-c\"><strong>What is an abstract class in C++?<\/strong><\/h3>\n\n\n\n<p>An abstract class in C++ is such that cannot be used directly and is used to form a base class for others to inherit from.<\/p>\n\n\n\n<p>If you create an object for an abstract class the compiler will throw an error at you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-containership-in-c\"><strong>What is containership in C++?<\/strong><\/h3>\n\n\n\n<p>Containership in C++ is a relationship in which a class's object is nested within another class. The class that contains the object is called a container class and the class whose object is stored is called a contained class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-data-hiding-in-c\"><strong>What is data hiding in C++?<\/strong><\/h3>\n\n\n\n<p>An object-oriented technique of hiding data members is called data hiding. In other words, giving restricted access to the data members so as to maintain object integrity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"polymorphism-concept\"><strong>Polymorphism Concept<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Im28uSWRrQY_OUSEyw6e1ZLBCKMYOoU5kIg-49QHgEKTztn1pB66DPqaJu3vy4yRj1B9X1n0V9OY_KBK7FVEzvoVXxLvR_-aucoxwlaZ8RMK1DAFKnkcRPORqjI5yxZwWNqk6Fn304HZN1AIe8o0WRAUsm1eOrQnpGfJHWz3eXid6GopdpV-B1lnEg\" alt=\"polymorphism in C++\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-runtime-polymorphism-in-c\"><strong>What is runtime polymorphism in C++?<\/strong><\/h3>\n\n\n\n<p>Polymorphism means having many forms whether it is a function or operator in programming.<\/p>\n\n\n\n<p>Runtime polymorphism is achieved by function overriding.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;bits\/stdc++.h&gt; \n\nusing namespace std; \n\nclass parent\n\n{ \n\npublic: \n\n    void print() \n\n    { cout&lt;&lt; \"\"base class\"\"; } \n\n}; \n\nclass child:public parent\n\n{ \n\npublic: \n\n    void print() \n\n    { cout&lt;&lt; \"\"derived class\"\"; } \n\n}; \n\nint main()  \n\n{ \n\n    parent *p; \n\n    child c; \n\n    p = &amp;c; \n\n    \/\/virtual function, binded at runtime (Runtime polymorphism) \n\n    p-&gt;print();  \n\n    return 0; \n\n} <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-copy-constructor-in-c\"><strong>What is copy constructor in C++?<\/strong><\/h3>\n\n\n\n<p>A <a href=\"https:\/\/www.mygreatlearning.com\/blog\/copy-constructor-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\">copy constructor in c++<\/a> is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. <br>The syntax for copy constructor is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclassname (const classname &amp;amp;obj) { \n\n   \/\/ body of constructor \n\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-is-modularity-introduced-in-c\"><strong>How is modularity introduced in C++?<\/strong><\/h3>\n\n\n\n<p>Modularity is a way of mapping encapsulated abstractions into real and physical modules which is closely related to Encapsulation. It is a concept in which separate programs are divided into separate modules.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">For example, when building a house it is built in modular way. First foundation is laid, then structure is made and so on.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-the-size-of-an-empty-class-in-c\"><strong>What is the size of an empty class in C++?<\/strong><\/h3>\n\n\n\n<p>The size of an empty class is 1 byte generally just to ensure that the two different objects will have different addresses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c-programming-interview-questions\"><strong>C++ Programming Interview Questions<\/strong><\/h2>\n\n\n\n<p>Programming is an important aspect for any programmer or developer. This section of the blog talks about c++ interview questions that will be beneficial to programming. Here is the list of the top 20 c++ programming questions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-write-hello-world-in-c\"><strong>How to write hello world in C++?<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>Hello world in C++ is as follows:\n#include &lt;iostream&gt;\nint main()\n{\n  std::cout &lt;&lt; \"Hello, World!\";\n  return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-input-string-in-c\"><strong>How to input string in C++?<\/strong><\/h3>\n\n\n\n<p>There are three ways to input a string, using cin, get, and getline. All three methods are mentioned in the sample program below.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main()\n{\n    char s&#091;10];\n\n    cout &lt;&lt; \"Enter a string: \";\n    cin &gt;&gt; str;\n   \n    cout &lt;&lt; \"nEnter another string: \";\n    cin.get(s, 10);\n\n    getline(cin, str);\n    \n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-reverse-a-string-in-c\"><strong>How to reverse a string in C++?<\/strong><\/h3>\n\n\n\n<p>To reverse a string, a sample code is mentioned below.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include&lt;iostream&gt;\n#include&lt;string.h&gt;\nusing namespace std;\nint main ()\n{\n    char n&#091;50], t;\n    int i, j;\n    cout &lt;&lt; \"Enter a string : \";\n    gets(n);\n    i = strlen(n) - 1;\n    for (j = 0; j &lt; i; j++,i--)\n    {\n        t = s&#091;j];\n        s&#091;j] = s&#091;i];\n        s&#091;i] = t;\n    }\n    cout &lt;&lt; \"nReverse string : \" &lt;&lt; s;\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-convert-integer-to-string-in-c\"><strong>How to convert integer to string in C++?<\/strong><\/h3>\n\n\n\n<p>There are 2 approaches to convert integer variables to string. Both the approaches with a sample code are mentioned below.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>Approach-1\n#include&lt;iostream&gt; \n#include&lt;string&gt; \nusing namespace std;\nvoid main() \n{ \n    int n= 1; \n    string s= to_string(n); \n    cout &lt;&lt; s;\n}\n\nApproach-2\n\n#include&lt;iostream&gt; \n#include &lt;sstream&gt;  \n#include &lt;string&gt; \nusing namespace std; \nint main() \n{ \n    int n = 17; \n  \n    \/\/ declaring output string stream \n    ostringstream s1; \n  \n    \/\/ Sending a number as a stream into output str\n    s&lt;&lt; n; \n    \/\/ the str() converts number into string \n    string fin = s.str(); \n    \/\/ Displaying the string\n    cout &lt;&lt; fin; \n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-input-string-in-c-with-spaces\"><strong>How to input string in C++ with spaces?<\/strong><\/h3>\n\n\n\n<p>The code to input a string in C++ with spaces is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt; \n#include &lt;string&gt; \nusing namespace std; \n  \nint main() \n{ \n    string s; \n  \n    cout &lt;&lt; \"Enter the sentence\"; \n    getline(cin, s); \n    cout &lt;&lt; str;\n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-dynamically-allocate-a-2d-array-in-c\"><strong>How to dynamically allocate a 2d array in C++?<\/strong><\/h3>\n\n\n\n<p>There are several methods by which one can allocate memory to 2D array dynamically one of which is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt; \nint main() \n{ \n    int row = 2, col = 2; \n    int* a =  new int&#091;row * col];\n  \n    int i, j, count = 0; \n    for (i = 0; i &lt;  row; i++) \n      for (j = 0; j &lt; col; j++) \n         *(a+ i*col + j) = count++; \n  \n    for (i = 0; i &lt;  row; i++) \n      for (j = 0; j &lt; col; j++) \n         printf(\"%d \", *(a + i*col + j)); \n  \n    delete&#091; ] a;\n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-use-goto-statement-in-c\"><strong>How to use goto statement in C++ ?<\/strong><\/h3>\n\n\n\n<p>Goto statement provided unconditional jump in the code.<\/p>\n\n\n\n<p>The syntax is<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n goto label;\nlabel: statement;\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\n \nvoid main () {\n    float d, avg, add = 0.0;\n    int j, n;\n    cin &gt;&gt; n;\n\n    for(j = 1; j &lt;= n; ++j)\n    {\n        cout &lt;&lt; \"Enter number\" &lt;&lt; i;\n        cin &gt;&gt; d;\n        \n        if(d &lt; 0.0)\n        {\n               goto jump;\n        } \n        add+= d;\n    }\n    \njump:\n    avg = add\/ (j- 1);\n    cout &lt;&lt; avg;\n  }\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-function-overriding-in-c\"><strong>What is function overriding in C++?<\/strong><\/h3>\n\n\n\n<p>When a function with same name is present in both parent and child class then it is called function overriding.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\nclass parent {\npublic:\n   void display(){\n      cout&lt;&lt;\"Parent Class\";\n   }\n};\nclass child: public parent{\npublic:\n   void display() {\n      cout&lt;&lt;\"Child Class\";\n   }\n};\nint main() {\n   child o = parent();\n   o.display();\n   return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-bool-in-c\"><strong>What is bool in C++?<\/strong><\/h3>\n\n\n\n<p>Bool is a data type in C++ which takes two values- True and False. <\/p>\n\n\n\n<p>The syntax is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nbool b1 = true;\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include&lt;iostream&gt; \nusing namespace std; \nint main() \n{ \n    int a= 60, b= 70; \n    bool c, d; \n    c= a== b; \/\/ false \n      \n    c= a&lt; b; \/\/ true \n      \n    cout &lt;&lt;b1; \n    cout &lt;&lt; b2 ; \n          \n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-set-decimal-places-in-c\"><strong>How to set decimal places in C++ ?<\/strong><\/h3>\n\n\n\n<p>For limiting the decimal places in C++ there are five functions : floor(), ceil(), trunc(), round() and setprecision(). Out of these five, only setprecision() function is used for setting the decimal places to put as output. All the functions are mentioned in the following sample code.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include&lt;bits\/stdc++.h&gt; \nusing namespace std; \n  \nint main() \n{ \n    float a =33333;\n    cout &lt;&lt; floor(a) &lt;&lt; endl; \n    cout &lt;&lt; ceil(a) &lt;&lt; endl;\n    cout &lt;&lt; trunc(a) &lt;&lt; endl;\n    cout &lt;&lt; round(a) &lt;&lt; endl;\n    cout &lt;&lt; setprecision(2) &lt;&lt; a;  \n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-get-absolute-value-in-c\"><strong>How to get absolute value in C++?<\/strong><\/h3>\n\n\n\n<p>In C++, there are three functions in the cstdlib header file to return the absolute value of the integer. Those are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>abs()<\/li>\n\n\n\n<li>labs()<\/li>\n\n\n\n<li>llabs()<\/li>\n<\/ul>\n\n\n\n<p>The syntax for all the functions is same<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n function_name(integer value)\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>The difference lies in the range for integer value being passed as an argument. <\/li>\n\n\n\n<li>For abs() its type int in C++. <\/li>\n\n\n\n<li>For labs(), its type long int in C++ <\/li>\n\n\n\n<li>For llabs() its long long int in C++.<\/li>\n<\/ul>\n\n\n\n<p>The sample code for illustrating the three functions is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;cstdlib&gt; \n#include &lt;iostream&gt; \n  \nusing namespace std; \n  \nint main() \n{ \n    int a, b, c; \n \n    a = abs(22); \n    b= labs(1234355L); \n    c= llabs(1234863551LL);\n    cout &lt;&lt; a; \n    cout &lt;&lt; b; \n    cout&lt;&lt; c;\n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-concatenate-string-in-c\"><strong>How to concatenate string in C++ ?<\/strong><\/h3>\n\n\n\n<p>The<a href=\"https:\/\/www.mygreatlearning.com\/blog\/strings-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\"> strings in C++<\/a> can be concatenated in two ways- one considering them string objects and the second concatenating them C-style strings.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main()\n{\n    string s_1, s_2, fin;\n    cout &lt;&lt; \"Enter string\";\n    getline (cin, s_1);\n    cout &lt;&lt; \"Enter string \";\n    getline (cin, s_2);\n    fin= s_1 + s_2;\n    cout &lt;&lt; fin;\n\n    char str1&#091;50], str2&#091;50], fin&#091;100];\n\n    cout &lt;&lt; \"Enter string\";\n    cin.getline(str1, 50);\n\n    cout &lt;&lt; \"Enter string\";\n    cin.getline(str2, 50);\n\n    strcat(str1, str2); \n\n    cout &lt;&lt; \"str1 = \" &lt;&lt; str1 &lt;&lt; endl;\n    cout &lt;&lt; \"str2 = \" &lt;&lt; str2;\n\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-convert-char-to-int-in-c\"><strong>How to convert char to int in C++ ?<\/strong><\/h3>\n\n\n\n<p>There are three methods for converting char variable to int type variable. These are as follows: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>atoi()<\/li>\n\n\n\n<li>sscanf()<\/li>\n\n\n\n<li>typecasting<\/li>\n<\/ul>\n\n\n\n<p>A sample code depicting all three functions are as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include&lt;stdio.h&gt;\n#include&lt;stdlib.h&gt;\nint main() {\n   char *s = \"6790\";\n   char d = 's';\n   int a,b,c;\n\n   sscanf(s, \"%d\", &amp;a); \/\/ Using sscanf\n   printf(\"a : %d\", a);\n\n   b = atoi(s); \/\/ Using atoi()\n   printf(\u201cb : %d\", b);\n\n   c = (int)(d); \/\/ Using typecasting\n   printf(\"c : %d\", c);\n\n   return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-generate-random-numbers-in-c-with-a-range\"><strong>How to generate random numbers in C++ with a range?<\/strong><\/h3>\n\n\n\n<p>Using the rand() function we can generate random numbers in C++ within a range.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\n#include &lt;random&gt;\nint main()\n{\n   int max=100, min=54,i;\n   int range = max - min + 1;\n   for (i=min; i&lt;max;i++)\n    {\n        int num = rand() % range + min;\n        cout&lt;&lt;num;\n    }\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-find-absolute-value-in-c\"><strong>How to find absolute value in C++?<\/strong><\/h3>\n\n\n\n<p>To find the absolute value in c++, we can use abs() function. The abs() function in C++ returns the absolute value of an integer number.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\n#include &lt;cstdlib&gt;\nusing namespace std;\n\nint main()\n{\n        int a=3.456;\n        int x = abs(a);\n        cout &lt;&lt; x;\n            return 0;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-write-a-class-in-c\"><strong>How to write a class in C++?<\/strong><\/h3>\n\n\n\n<p>A class in C++ is the building block that leads to Object-Oriented programming and is a user-defined data type which holds data and functions. The syntax to write a class in C++ is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>Class (keyword) Class_Name (this is user defined)\n{\n    Access specifier: \/\/ private, public, protected\n    Data members \/\/int, char, float, double etc. variables to be used\n    Member function() { }  \/\/ Methods to access data members\n};     \/\/Class end\nFor example:\nclass Sample\n{ \n    \/\/ Access specifier \n    private: \n  \n    \/\/ Data Members \n    string s; \n  \n    \/\/ Member Functions() \n    void printname() \n    { \n       cout &lt;&lt; s; \n    } \n};\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-use-strcmp-function-in-c\"><strong>How to use strcmp function in C++?<\/strong><\/h3>\n\n\n\n<p>strcmp() function is an in-built function of &lt;string.h&gt; header file which takes two strings as arguments and compares these two strings lexicographically.<\/p>\n\n\n\n<p>The syntax of the function is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nint strcmp(const char *l, const char *r );\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include&lt;stdio.h&gt; \n#include&lt;string.h&gt; \nint main() \n{  \n    \/\/ z has greater ASCII value than g \n    char a&#091;] = \"zfz\"; \n    char b&#091;] = \"gfg\"; \n      \n    int r = strcmp(a, b); \n      \n    if (r==0) \n        printf(\"Strings are equal\"); \n    else \n        printf(\"Strings are unequal\"); \n          \n    printf(\"%d\" , r); \n      \n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"how-to-write-to-a-file-in-c\"><strong>How to write to a file in C++?<\/strong><\/h3>\n\n\n\n<p>A file is read in c++ using a fstream header file.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt; \n#include &lt;fstream&gt;  \nusing namespace std;\nint main() \n{ \n    ofstream fout; \n    string r; \n  \n    fout.open(\"test.txt\"); \n\n    while (fout) {\n        getline(cin, r); \n        if (r == \"-1\") \n            break; \n        fout &lt;&lt; line &lt;&lt; endl; \n    } \n    fout.close(); \n  \n    ifstream fin; \n    fin.open(\"test.txt\"); \n    while (fin) { \n         getline(fin, line); \n          cout &lt;&lt; line &lt;&lt; endl; \n    } \n    fin.close(); \n    return 0; \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading is-style-numbered\" id=\"what-is-stringstream-in-c\"><strong>What is stringstream in C++?<\/strong><\/h3>\n\n\n\n<p>Stringstream is a class in c++ that associates a string object with a stream allowing to read from the string as if it were a stream. <\/p>\n\n\n\n<p>Syntax is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstringstream string_name(str);\n<\/pre><\/div>\n\n\n<p>Basic operations are as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>clear()\nstr()\n&lt;&lt;\n&gt;&gt;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c-interview-questions-faqs\"><strong>C++ Interview Questions FAQS<\/strong><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1662028672137\"><strong class=\"schema-faq-question\"><strong>What are the important topics in C++?<\/strong><\/strong> <p class=\"schema-faq-answer\">\u00a0The significant topics in C++ are abstraction, control statements, constructor, objects, and classes, inheritance, destructor, static, polymorphism, abstract class, interface, namespace, exception handling, encapsulation, arrays, strings, and File IO, to name a few.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028692471\"><strong class=\"schema-faq-question\"><strong>How do I prepare for C++?<\/strong><\/strong> <p class=\"schema-faq-answer\">As you start preparing for C++, you need to be sure that you are the basic data structures as well as algorithms. These are the basic things that you are most likely to be asked about rather than more complicated concepts. To put it simply, you have to be very clear about the fundamentals of C++ syntax.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028708571\"><strong class=\"schema-faq-question\"><strong>What is C++ best used for?<\/strong><\/strong> <p class=\"schema-faq-answer\">C++ is used especially when a low-level programming language is needed. C++ is mostly used for graphics-heavy software, which includes a photo and video editing apps, games, and browsers; while, C is usually used for OS kernels and embedded devices.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028724839\"><strong class=\"schema-faq-question\"><strong>What are the basics of C++?<\/strong><\/strong> <p class=\"schema-faq-answer\">The basic elements of C++ are input, output, conditional, arithmetic, and looping. To know more about it, you first need to understand the concept of C++.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028739080\"><strong class=\"schema-faq-question\"><strong>How to code in C++?<\/strong><\/strong> <p class=\"schema-faq-answer\">You have to start it by choosing a file name that explains the purpose of the program. The next step will include building the Executable Code: Compile and Link (aka Build) the source code \" hello. cpp \" into executable code (\" hello.exe \" in Windows or \" hello \" in UNIX\/Linux\/Mac). On IDE (like CodeBlocks), push the \"Build\" button.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028760764\"><strong class=\"schema-faq-question\"><strong>What is C++ and its features?<\/strong><\/strong> <p class=\"schema-faq-answer\">C++ is basically an object-oriented programming (OOP) language that many consider the best language that helps in creating large-scale applications. The features of C++ include Object Oriented, Simple, Platform Dependent, Mid-level programming language, Structured programming language, Rich Library, Memory Management, and Powerful &amp; Fast.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028778421\"><strong class=\"schema-faq-question\"><strong>\u00a0Is C++ hard to learn?<\/strong><\/strong> <p class=\"schema-faq-answer\">The syntax of C++ is not difficult to understand for most people. And it becomes especially easy to learn if you already know what C is. However, the versatility of C++ makes it a powerful language, which is why some find it a bit hard to learn.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028795508\"><strong class=\"schema-faq-question\"><strong>Is Java better than C++?<\/strong><\/strong> <p class=\"schema-faq-answer\">Java is usually a high-level, object-oriented, and interpreted language, which uses objects. On the other hand, C uses functions. Java is mostly found easier to learn by many since it is high level, while C performs faster since it is closer to machine code.<br \/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662028816641\"><strong class=\"schema-faq-question\"><strong>Why is C++ called OOP?<\/strong><\/strong> <p class=\"schema-faq-answer\">The reason why C++ is called OOP or Object Oriented Programming is that C++ sees a problem as objects that are involved rather than the process to do it.<br \/><\/p> <\/div> <\/div>\n\n\n\n<p>This brings us to the end of the blog on c++ interview questions. We hope you are now well-equipped with the kind of questions that may be asked during an Interview. Wondering where to learn the highly coveted in-demand skills for free? Check out the courses on <a href=\"https:\/\/www.mygreatlearning.com\/academy\" target=\"_blank\" rel=\"noreferrer noopener\">Great Learning Academy<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 the C programming language. The first set of c++ interview questions is curated for freshers and talks about the basic c++ [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":80861,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36801],"content_type":[36249],"class_list":["post-21307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-c-programming","content_type-interview-questions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Top 120+ C++ Interview Questions<\/title>\n<meta name=\"description\" content=\"C++ interview questions: Top 120+ frequently asked C++ Interview Questions for beginners to advanced levels. It helps to crack your interview.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Top 100 C++ Interview Questions and Answers\" \/>\n<meta property=\"og:description\" content=\"C++ interview questions: Top 120+ frequently asked C++ Interview Questions for beginners to advanced levels. It helps to crack your interview.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-08T04:40:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-22T10:01:53+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Top 100 C++ Interview Questions and Answers\",\"datePublished\":\"2023-11-08T04:40:59+00:00\",\"dateModified\":\"2025-01-22T10:01:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/\"},\"wordCount\":4879,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Blog-Featured-Image.jpg\",\"keywords\":[\"C++ Programming\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/\",\"name\":\"Top 120+ C++ Interview Questions\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Blog-Featured-Image.jpg\",\"datePublished\":\"2023-11-08T04:40:59+00:00\",\"dateModified\":\"2025-01-22T10:01:53+00:00\",\"description\":\"C++ interview questions: Top 120+ frequently asked C++ Interview Questions for beginners to advanced levels. It helps to crack your interview.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028672137\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028692471\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028708571\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028724839\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028739080\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028760764\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028778421\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028795508\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028816641\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Blog-Featured-Image.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Blog-Featured-Image.jpg\",\"width\":1200,\"height\":628,\"caption\":\"C++ Interview Questions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Top 100 C++ Interview Questions and Answers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028672137\",\"position\":1,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028672137\",\"name\":\"u003cstrongu003eWhat are the important topics in C++?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"\u00a0The significant topics in C++ are abstraction, control statements, constructor, objects, and classes, inheritance, destructor, static, polymorphism, abstract class, interface, namespace, exception handling, encapsulation, arrays, strings, and File IO, to name a few.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028692471\",\"position\":2,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028692471\",\"name\":\"u003cstrongu003eHow do I prepare for C++?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"As you start preparing for C++, you need to be sure that you are the basic data structures as well as algorithms. These are the basic things that you are most likely to be asked about rather than more complicated concepts. To put it simply, you have to be very clear about the fundamentals of C++ syntax.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028708571\",\"position\":3,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028708571\",\"name\":\"u003cstrongu003eWhat is C++ best used for?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"C++ is used especially when a low-level programming language is needed. C++ is mostly used for graphics-heavy software, which includes a photo and video editing apps, games, and browsers; while, C is usually used for OS kernels and embedded devices.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028724839\",\"position\":4,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028724839\",\"name\":\"u003cstrongu003eWhat are the basics of C++?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The basic elements of C++ are input, output, conditional, arithmetic, and looping. To know more about it, you first need to understand the concept of C++.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028739080\",\"position\":5,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028739080\",\"name\":\"u003cstrongu003eHow to code in C++?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"You have to start it by choosing a file name that explains the purpose of the program. The next step will include building the Executable Code: Compile and Link (aka Build) the source code u0022 hello. cpp u0022 into executable code (u0022 hello.exe u0022 in Windows or u0022 hello u0022 in UNIX\\\/Linux\\\/Mac). On IDE (like CodeBlocks), push the u0022Buildu0022 button.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028760764\",\"position\":6,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028760764\",\"name\":\"u003cstrongu003eWhat is C++ and its features?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"C++ is basically an object-oriented programming (OOP) language that many consider the best language that helps in creating large-scale applications. The features of C++ include Object Oriented, Simple, Platform Dependent, Mid-level programming language, Structured programming language, Rich Library, Memory Management, and Powerful u0026amp; Fast.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028778421\",\"position\":7,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028778421\",\"name\":\"u003cstrongu003e\u00a0Is C++ hard to learn?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The syntax of C++ is not difficult to understand for most people. And it becomes especially easy to learn if you already know what C is. However, the versatility of C++ makes it a powerful language, which is why some find it a bit hard to learn.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028795508\",\"position\":8,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028795508\",\"name\":\"u003cstrongu003eIs Java better than C++?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Java is usually a high-level, object-oriented, and interpreted language, which uses objects. On the other hand, C uses functions. Java is mostly found easier to learn by many since it is high level, while C performs faster since it is closer to machine code.u003cbr\\\/u003e\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028816641\",\"position\":9,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/cpp-interview-questions\\\/#faq-question-1662028816641\",\"name\":\"u003cstrongu003eWhy is C++ called OOP?u003c\\\/strongu003e\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The reason why C++ is called OOP or Object Oriented Programming is that C++ sees a problem as objects that are involved rather than the process to do it.u003cbr\\\/u003e\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Top 120+ C++ Interview Questions","description":"C++ interview questions: Top 120+ frequently asked C++ Interview Questions for beginners to advanced levels. It helps to crack your interview.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"Top 100 C++ Interview Questions and Answers","og_description":"C++ interview questions: Top 120+ frequently asked C++ Interview Questions for beginners to advanced levels. It helps to crack your interview.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2023-11-08T04:40:59+00:00","article_modified_time":"2025-01-22T10:01:53+00:00","og_image":[{"width":1200,"height":628,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"22 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Top 100 C++ Interview Questions and Answers","datePublished":"2023-11-08T04:40:59+00:00","dateModified":"2025-01-22T10:01:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/"},"wordCount":4879,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg","keywords":["C++ Programming"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/","url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/","name":"Top 120+ C++ Interview Questions","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg","datePublished":"2023-11-08T04:40:59+00:00","dateModified":"2025-01-22T10:01:53+00:00","description":"C++ interview questions: Top 120+ frequently asked C++ Interview Questions for beginners to advanced levels. It helps to crack your interview.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028672137"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028692471"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028708571"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028724839"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028739080"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028760764"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028778421"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028795508"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028816641"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg","width":1200,"height":628,"caption":"C++ Interview Questions"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Top 100 C++ Interview Questions and Answers"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028672137","position":1,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028672137","name":"u003cstrongu003eWhat are the important topics in C++?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\u00a0The significant topics in C++ are abstraction, control statements, constructor, objects, and classes, inheritance, destructor, static, polymorphism, abstract class, interface, namespace, exception handling, encapsulation, arrays, strings, and File IO, to name a few.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028692471","position":2,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028692471","name":"u003cstrongu003eHow do I prepare for C++?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"As you start preparing for C++, you need to be sure that you are the basic data structures as well as algorithms. These are the basic things that you are most likely to be asked about rather than more complicated concepts. To put it simply, you have to be very clear about the fundamentals of C++ syntax.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028708571","position":3,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028708571","name":"u003cstrongu003eWhat is C++ best used for?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"C++ is used especially when a low-level programming language is needed. C++ is mostly used for graphics-heavy software, which includes a photo and video editing apps, games, and browsers; while, C is usually used for OS kernels and embedded devices.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028724839","position":4,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028724839","name":"u003cstrongu003eWhat are the basics of C++?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The basic elements of C++ are input, output, conditional, arithmetic, and looping. To know more about it, you first need to understand the concept of C++.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028739080","position":5,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028739080","name":"u003cstrongu003eHow to code in C++?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You have to start it by choosing a file name that explains the purpose of the program. The next step will include building the Executable Code: Compile and Link (aka Build) the source code u0022 hello. cpp u0022 into executable code (u0022 hello.exe u0022 in Windows or u0022 hello u0022 in UNIX\/Linux\/Mac). On IDE (like CodeBlocks), push the u0022Buildu0022 button.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028760764","position":6,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028760764","name":"u003cstrongu003eWhat is C++ and its features?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"C++ is basically an object-oriented programming (OOP) language that many consider the best language that helps in creating large-scale applications. The features of C++ include Object Oriented, Simple, Platform Dependent, Mid-level programming language, Structured programming language, Rich Library, Memory Management, and Powerful u0026amp; Fast.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028778421","position":7,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028778421","name":"u003cstrongu003e\u00a0Is C++ hard to learn?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The syntax of C++ is not difficult to understand for most people. And it becomes especially easy to learn if you already know what C is. However, the versatility of C++ makes it a powerful language, which is why some find it a bit hard to learn.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028795508","position":8,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028795508","name":"u003cstrongu003eIs Java better than C++?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Java is usually a high-level, object-oriented, and interpreted language, which uses objects. On the other hand, C uses functions. Java is mostly found easier to learn by many since it is high level, while C performs faster since it is closer to machine code.u003cbr\/u003e","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028816641","position":9,"url":"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/#faq-question-1662028816641","name":"u003cstrongu003eWhy is C++ called OOP?u003c\/strongu003e","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The reason why C++ is called OOP or Object Oriented Programming is that C++ sees a problem as objects that are involved rather than the process to do it.u003cbr\/u003e","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg",1200,628,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-300x157.jpg",300,157,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-768x402.jpg",768,402,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-1024x536.jpg",1024,536,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg",1200,628,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image.jpg",1200,628,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-640x628.jpg",640,628,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/01\/Blog-Featured-Image-150x79.jpg",150,79,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"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 the C programming language. The first set of c++ interview questions is curated for freshers and talks about the basic c++&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/21307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=21307"}],"version-history":[{"count":284,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/21307\/revisions"}],"predecessor-version":[{"id":114861,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/21307\/revisions\/114861"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/80861"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=21307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=21307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=21307"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=21307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}