

{"id":61878,"date":"2019-07-12T17:18:13","date_gmt":"2019-07-12T11:48:13","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=61878"},"modified":"2020-02-03T16:25:28","modified_gmt":"2020-02-03T10:55:28","slug":"cpp-interview-questions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/","title":{"rendered":"C++ Interview Questions &amp; Answers (Prepared by Industry Experts)"},"content":{"rendered":"<p>Wouldn\u2019t it be great if you were aware of the C++ questions that would be asked in your next interview? While you cannot read the mind of the interviewer, you can certainly anticipate questions with our collection of important C++ interview questions and their solutions.<\/p>\n<p>These C++ questions will assist you in cracking interviews. You will be much more confident about taking on interviews after you have bolstered your foundations with these quintessential questions.<\/p>\n<p><em>So, ace your interviews and jumpstart your career.<\/em><\/p>\n<h2>Latest C++ Interview Questions<\/h2>\n<p><strong>Q.1 What is the difference between a reference and a pointer?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Pointers and References are two different concepts. A <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/pointer-in-c-and-cpp\/\">pointer in C++<\/a><\/strong><\/em> <em>is basically a variable that stores the memory address of another variable<\/em>. While references <em>act as an alias name for an existing variable that needs to be initialized at the time of declaration<\/em>. This is not the case with pointers.<\/p>\n<p>Here are a few more differences between the two:<\/p>\n<table dir=\"ltr\">\n<colgroup>\n<col width=\"345\" \/>\n<col width=\"374\" \/><\/colgroup>\n<tbody>\n<tr>\n<td><strong>Pointers<\/strong><\/td>\n<td><strong>Reference\u00a0<\/strong><\/td>\n<\/tr>\n<tr>\n<td>In any C++ program, a pointer has the provision to point to several objects.<\/td>\n<td>In any C++ program, references can only refer to only one object, that is, a reference cannot rebound.<\/td>\n<\/tr>\n<tr>\n<td>We can create an array of pointers<\/td>\n<td>We cannot create an array of references as it is impossible to initialize a value to each element of the array at the time of declaration.<\/td>\n<\/tr>\n<tr>\n<td>The \u201c*\u201d operator is needed to de-reference a pointer<\/td>\n<td>No such operator is required to de-reference an operator.<\/td>\n<\/tr>\n<tr>\n<td>A pointer can hold a NULL value<\/td>\n<td>A reference cannot hold a null value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Q.2 What was the need to introduce classes when C++ already supports structures?<\/strong><\/p>\n<p><strong>Ans.\u00a0<em><a href=\"https:\/\/data-flair.training\/blogs\/cpp-class-and-object\/\">Classes and objects in C++<\/a><\/em><\/strong> <em>provide a way to implement the concept of object-oriented programming like data abstraction, encapsulation, hiding, inheritance, and polymorphism<\/em>. These features help in representing real-world problems and propose algorithms to solve them.<\/p>\n<p>These features cannot be implemented with the help of structures.<\/p>\n<p>For instance, the public, private and protected mode of a class helps in keeping the data secure whereas, in structures, there is only visibility mode, that is, public by default that does not ensure any data security.<\/p>\n<p><strong>Q.3 Which is the most preferred loop for traversing an array and why?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The most preferable loop for traversing an array is the \u201c<strong>for loop<\/strong>\u201d since an array uses the index of the element for traversal. Using the for loop ensures easy access to the element.<\/p>\n<p>For instance,<\/p>\n<p>Array [ 5 ] = {10, 20, 30, 40, 50}<\/p>\n<p>Using the for <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/loops-in-c-and-c-plus-plus\/\">loop in C++<\/a><\/strong><\/em>,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for (int i = 0; i &lt; 5; i++ )\r\n{\r\ncout &lt;&lt; Array [ i ];\r\n}<\/pre>\n<p>Basically, an iterative block is required along with a looping variable \u2018i\u2019 serving an index counter, incrementing from:<\/p>\n<p>0 to ((length of the array) &#8211; 1)<\/p>\n<p><em><a href=\"https:\/\/data-flair.training\/blogs\/arrays-in-c-and-cpp\/\"><strong>Get the Samurai Technique to Learn <\/strong><strong>Arrays in C++<\/strong><\/a><\/em><\/p>\n<p><strong>Q.4 What is the difference between the local and global scope of a variable and what is their order of precedence if they both are of the same name?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The<em> local scope of a variable allows the variable to work inside a restricted block of code.<\/em> For instance, if it is declared inside a function, you cannot access it from the main function without calling the function whereas the <em>global scope of a variable allows the variable to be accessible throughout the entire program<\/em>.<\/p>\n<p>It is a well-established fact that whenever a program has a local and global variable, precedence is given to the local variable within that program.<\/p>\n<p><strong>Q.5 What is the difference between a++ and ++a?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>a++ refers to <em>post-increment operation<\/em>. The C++ compiler first uses the value of a and then increments it.<\/p>\n<p>++a refers to the <em>pre-increment operation<\/em>. The C++ compiler first increments the value of a++ and then uses a.<\/p>\n<p><strong>Q.6 How would you establish the relationship between abstraction and encapsulation?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Data abstraction refers to <em>representing only the important features of the real-world object in the C++ program<\/em>. This entire process does not include any explanation and background details of the code. Abstraction is implemented with the help of classes and objects, whereas, data encapsulation is the most significant feature of a class.<\/p>\n<p><em><strong><a href=\"https:\/\/data-flair.training\/blogs\/data-encapsulation-in-cpp\/\">Data encapsulation in C++<\/a><\/strong><\/em> refers to the <em>wrapping up of data members and member functions that operate on the data as a single unit, called the class<\/em>. Encapsulation prevents free access to the members of the class.<\/p>\n<p><strong>Q.7 How is object-oriented programming different from procedural programming?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>In object-oriented programming, <em>the entire program is divided into smaller units called objects and works on the bottom-up approach<\/em>. Whereas, in procedural programming, the entire program is divided into smaller units called functions and works on the top-down approach.<\/p>\n<p>In a nutshell, procedural programming <em>does not provide any data security whereas, in contrast to it, object-oriented programming ensures data security with the help of access specifiers, proving to be more secure and efficient<\/em>.<\/p>\n<p>C++ supports object-oriented programming whereas C supports procedural programming.<\/p>\n<p><strong>Q.8 What are the similarities between constructors and destructors?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Both <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/constructor-and-destructor-in-cpp\/\">constructors and destructors in C++<\/a><\/strong><\/em> <em>need to be declared within the class with the same name as that of the class.<\/em> Even if they aren\u2019t declared inside the class, they exist by default but in this case, we can use them only to allocate and deallocate memory from the objects of a class, whenever the object is declared or deleted.<\/p>\n<p><strong>Q.9 Why cannot a constructor and destructor be inherited?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Both<em> constructors and destructors are not inherited as each class have its own constructo<\/em>r. Since each object of a class consists of multiple parts, a base class part and derived class part, constructors and destructors are not inherited.<\/p>\n<p><strong>Q.10 Consider the following C++ code segment and answer the following questions associated with it:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nclass Test\r\n{\r\nint ID;\r\nfloat max, min, marks;\r\npublic: \r\nTest() \/\/ Function 1\r\n{\r\nID = 121;\r\nmax = 100;\r\nmin = 33.33;\r\nmarks = 75;\r\n}\r\n\r\nTest(int r_no, int Marks) \/\/ Function 2\r\n{\r\nID = r_no;\r\nmax = 100;\r\nmin = 33.33;\r\nmarks = Marks;\r\n}\r\n\r\n~Test() \/\/ Function 3\r\n{\r\ncout&lt;&lt;\"Finished Test\"&lt;&lt;endl;\r\n}\r\nvoid display() \/\/ Function 4\r\n{\r\ncout&lt;&lt;ID&lt;&lt;\"\\t\"&lt;&lt;max&lt;&lt;\"\\t\"&lt;&lt;\"\\t\"&lt;&lt;min&lt;&lt;endl;\r\ncout&lt;&lt;\"Your marks: \"&lt;&lt;marks&lt;&lt;endl;\r\n}\r\n}<\/pre>\n<p><strong>Q.10.1 Which OOP concept is illustrated through \u201cFunction 1\u201d and \u201cFunction 2\u201d together?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The concept of polymorphism and constructor overloading is represented by both the functions together.<\/p>\n<p><em><strong>Learn everything about <a href=\"https:\/\/data-flair.training\/blogs\/polymorphism-in-c-plus-plus\/\">Polymorphism in C++<\/a><\/strong><\/em><\/p>\n<p><strong>Q.10.2 What is \u201cFunction 3\u201d referred as and when would it be invoked?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>Function 3 refers to the destructor of the class. It is invoked as soon as the scope of the object of the class gets over.<\/p>\n<h2>C++ Coding Interview Questions and Answers<\/h2>\n<p><strong>Q.11 Predict the header files required to run this program and its output: (i1)<\/strong><\/p>\n<p><strong>(NOTE that the ASCII value of \u2018A\u2019 is 65)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">using namespace std;\r\n\r\nint main()\r\n{\r\n\r\nchar letter = 'A', new_letter;\r\nint value = 10, result;\r\nif(islower(letter))\r\nnew_letter = toupper(letter);\r\nelse \r\nnew_letter = value + letter;\r\nresult = new_letter + 10;\r\ncout&lt;&lt; letter &lt;&lt;\" has changed its value to \" &lt;&lt; result &lt;&lt;endl;\r\nreturn 0;\r\n}<\/pre>\n<p><strong>Ans.<\/strong>\u00a0The required header file is <strong>&lt;ctype.h&gt;<\/strong><\/p>\n<p>OUTPUT: A has changed its value to<strong> 85.<\/strong><\/p>\n<p><em><strong>You can create your <a href=\"https:\/\/data-flair.training\/blogs\/header-files-in-c-cpp\/\">Header Files in C++<\/a> in a few seconds.<\/strong><\/em><\/p>\n<p><strong>Q.12 Predict the output of the following code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nclass Gameplay\r\n{\r\nint level, points;\r\nchar type;\r\npublic:\r\nGameplay(char Gtype = 'A')\r\n{\r\nlevel = 1;\r\npoints = 0;\r\ntype = Gtype;\r\n}\r\nvoid play(int g);\r\nvoid upgrade();\r\nvoid display()\r\n{\r\ncout&lt;&lt;type&lt;&lt;\"*\"&lt;&lt;level&lt;&lt;endl;\r\ncout&lt;&lt;points&lt;&lt;endl;\r\n}\r\n};\r\n\r\nint main()\r\n{\r\n\r\nGameplay g1('P'), g2;\r\ng2.display();\r\ng1.play(10);\r\ng1.upgrade();\r\ng2.play(20);\r\ng1.display();\r\ng2.display();\r\n}\r\n\r\nvoid Gameplay :: upgrade()\r\n{\r\ntype = (type=='A')?'P':'A';\r\n}\r\nvoid Gameplay :: play(int g)\r\n{\r\npoints = points + g;\r\nif(points &gt; 50)\r\nlevel = 5;\r\nelse if(points &gt; 40)\r\nlevel = 4;\r\nelse\r\nlevel = 3;\r\n}<\/pre>\n<p><strong>Ans.<\/strong><\/p>\n<p>A*1<br \/>\n0<br \/>\nA*3<br \/>\n10<br \/>\nA*3<br \/>\n20<\/p>\n<p><strong>Q.13 Consider the following C++ code segment and answer the following questions associated with it:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class College\r\n{\r\nlong ID;\r\nstring city;\r\nprotected:\r\nstring Country;\r\npublic:\r\nCollege();\r\nvoid enroll();\r\nvoid print();\r\n};\r\nclass Department :: private College\r\n{\r\nlong Dcode[20];\r\nstring HOD;\r\nprotected:\r\ndouble budget;\r\npublic:\r\nDepartment();\r\nvoid enter();\r\nvoid display();\r\n};\r\nclass Student : public Department\r\n{\r\nlong r_no;\r\nstring name;\r\npublic:\r\nStudent();\r\nvoid get_admission();\r\nvoid view();\r\n};<\/pre>\n<p><strong>Q.13.1\u00a0Which type of inheritance is illustrated through the above C++ code?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The concept of multilevel inheritance has been illustrated through the above C++ code.<\/p>\n<p><strong>Q.13.2\u00a0Which member functions are directly accessible from the objects of the class \u201cStudent\u201d?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>The member functions that are directly accessible through the objects of class \u201cStudent\u201d are:<\/p>\n<p>get_admission();<br \/>\nview();<br \/>\nenter();<br \/>\ndisplay();<\/p>\n<p><strong>Q.13.3 Is it possible to directly call the function \u201cprint()\u201d of class Campus from an object of class \u201cDepartment\u201d?<\/strong><\/p>\n<p><strong>Ans.\u00a0<\/strong>In the above code segment, it is not possible to call the function \u201cprint()\u201d of class Campus as there is no such class named \u201cCampus\u201d in the given program.<\/p>\n<p><strong>Q.13.4 Which data members are directly accessible from the member functions of the class \u201cStudent\u201d?<\/strong><\/p>\n<p><strong>Ans.<\/strong>The data members that are directly accessible to the member function \u201cStudent\u201d are:<br \/>\nr_no;<br \/>\nname;<br \/>\nbudget;<\/p>\n<p><em><strong>Master the concept of <a href=\"https:\/\/data-flair.training\/blogs\/function-in-c-and-cpp\/\">Functions in C++ with Example<\/a><\/strong><\/em><\/p>\n<p><strong>Q.13.3 Write a C++ function to count the number of lowercase alphabets in a text file.<\/strong><\/p>\n<p><strong>Ans.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">int count_lowercase()\r\n{\r\nifstream fin(\"file_name.txt\");\r\nchar ch;\r\nint count = 0;\r\nwhile(!fin.eof())\r\n{\r\nfin&gt;&gt;ch;\r\nis(islower(ch))\r\ncount++;\r\n}\r\nfin.close();\r\nreturn count;\r\n}<\/pre>\n<p><strong>Q.14 If you are given a binary file named \u201cPhone.dat\u201d that consists of records of a phonebook directory, how would you copy the records of the file that have their AreaCode as \u201c400\u201d from \u201cPhone.dat\u201d to \u201cCopy.dat\u201d?<\/strong><\/p>\n<p><strong>The given binary file has the following content:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Directory\r\n{\r\nstring name, address;\r\nchar phone_no[15];\r\nchar area_code[5];\r\npublic:\r\nvoid input();\r\nvoid output();\r\nint checkcode(string ac)\r\n{\r\nreturn strcmp( area_code, ac)\r\n}\r\n};<\/pre>\n<p><strong>Ans.<\/strong> We will define a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Functional_(C%2B%2B)\">function<\/a> to perform the above-stated task:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">void copy400()\r\n{\r\nifstream fin;\r\nofstream fout;\r\nDirectory ph;\r\nfin.open(\"Phone.dat\", ios::in | ios::binary);\r\nfout.open(\"Copy.dat\", ios::out | ios::binary);\r\nwhile(!fin.eof())\r\n{\r\nfin.read((char*)&amp;ph. sizeof(ph));\r\nif(ph.checkcode(\"400\")==0)\r\nfout.write((char*)&amp;ph, sizeof(ph));\r\n}\r\nfin.close();\r\nfout.close();\r\n}<\/pre>\n<p><strong>Q.15 Write a C++ function to perform popping operation from a dynamic stack that contains the name of a book and its title. Consider the following definition:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">struct node\r\n{\r\nint book_no;\r\nchar book_name[30];\r\nnode *link;\r\n};<\/pre>\n<p><strong>Ans.\u00a0<\/strong>The function definition to pop the elements in the stack is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">void POP(node *top)\r\n{\r\ncout&lt;&lt;\"Popping the top element from the stack\"&lt;&lt;endl;\r\ncout&lt;&lt;\"The book number is: \"&lt;&lt; top-&gt;book_no &lt;&lt;endl;\r\ncout&lt;&lt;\"The book name is: \"&lt;&lt; top -&gt; book_name &lt;&lt;endl;\r\nnode *temp = top;\r\ntop = top -&gt; link;\r\ndelete(temp)\r\n}<\/pre>\n<p><strong>Q.16 Write a C++ function to perform insertion operation in a dynamic queue according to the following code definition:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">struct node\r\n{\r\nint ID;\r\nchar name[100];\r\nnode* next;\r\n};<\/pre>\n<p><strong>Ans.<\/strong> The function definition to insert the elements in the queue is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">void ENQUEUE(node *rear, int val, char data[])\r\n{\r\nnode*temp = new node;\r\ntemp -&gt; ID = val;\r\nstrcpy(temp -&gt; name,data);\r\ntemp -&gt; next = NULL;\r\nif(rear == NULL)\r\nrear = front = temp;\r\nelse\r\n{\r\nrear -&gt; next = temp;\r\nrear = temp;\r\n}\r\n}<\/pre>\n<p><strong>Q.17 How would you find the sum of two numbers without using the \u2018+\u2019 operator in C++?<\/strong><\/p>\n<p><strong>Ans.<\/strong> Here is a program that helps you find the sum of two numbers without using the \u2018+\u2019 <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/operators-in-c-and-cpp\/\">operator in C++<\/a><\/strong><\/em>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#include&lt;iostream&gt; \r\nusing namespace std;\r\n\r\nvoid sum(int n1, int n2)\r\n{\r\nint sum = -( -n1-n2 ); \r\ncout &lt;&lt; sum &lt;&lt; endl; \r\n}\r\nint main() \r\n{\r\nsum(5,5);\r\nsum(6,4); \r\nreturn 0;\r\n}<\/pre>\n<p><strong>Q.18 Find out the error in the following code segment in C++<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">int main()\r\n{\r\n\r\nconst int val = 10;\r\nconst int *const pointer = &amp;val;\r\n(*pointer)++;\r\nint data = 20;\r\npointer = &amp;data;\r\n}<\/pre>\n<p><strong>Ans.\u00a0<\/strong>It is an evident fact that the statements \u201c(*pointer)++\u201d and \u201cpointer = &amp;data\u201d cannot modify a constant object as the value of a constant variable cannot change throughout the entire program.<\/p>\n<p><strong>Q.19 What is the difference between typecasting and automatic type conversion? Explain with the help of an example.<\/strong><\/p>\n<p><strong>Ans. <em><a href=\"https:\/\/data-flair.training\/blogs\/typecasting-in-c-cpp\/\">Typecasting in C++<\/a><\/em><\/strong> is done by the programmer in order to convert a value from one data type to another data type.<\/p>\n<p>For example,<\/p>\n<p>float pi = (float) 22\/7;<\/p>\n<p>On the other hand, automatic type conversion is automatically done by the C++ compiler as and when required.<\/p>\n<p>For example,<\/p>\n<p>float value = 10;<\/p>\n<p><strong>Q.20 Why do we use templates in C++?<\/strong><\/p>\n<p><strong>Ans.<\/strong>\u00a0<em><strong><a href=\"https:\/\/data-flair.training\/blogs\/cpp-template\/\">Templates in C++<\/a><\/strong><\/em> are a quick and efficient way of achieving polymorphism, an important concept in OOP. It helps us in handling various types of parameters and hence reduces efforts in debugging and testing the code.<\/p>\n<h2>Summary<\/h2>\n<p>Hope, you can answer all the C++ interview questions. If not, refer our <em><a href=\"https:\/\/data-flair.training\/blogs\/category\/cpp\/\">C++ tutorials series<\/a><\/em> and prepare yourself.<\/p>\n<p>Feedback and suggestions are welcomed in the comment section.<\/p>\n<p>Get ready for <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/cpp-programming-interview-questions\/\">another set of Interview Questions for C++<\/a><\/strong><\/em>.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1477,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Functional_(C%2B%2B)&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250318112314\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Functional_(C%2B%2B)&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 08:38:06&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2025-12-09 08:38:06&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wouldn\u2019t it be great if you were aware of the C++ questions that would be asked in your next interview? While you cannot read the mind of the interviewer, you can certainly anticipate questions&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":63032,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20172],"tags":[20568,20486,20544,20482,20566,20567,20547,20483],"class_list":["post-61878","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpp","tag-best-c-interview-questions","tag-c-coding-interview-questions","tag-c-interview-questions-for-experienced","tag-c-interview-questions-for-freshers","tag-c-interview-questions","tag-c-programming-interview-questions","tag-latest-c-interview-questions","tag-top-c-interview-questions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C++ Interview Questions &amp; Answers (Prepared by Industry Experts) - DataFlair<\/title>\n<meta name=\"description\" content=\"C++ Interview Questions &amp; Answers help to build your confidence during interview and crack it easily. This is a collection of trending interview questions\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ Interview Questions &amp; Answers (Prepared by Industry Experts) - DataFlair\" \/>\n<meta property=\"og:description\" content=\"C++ Interview Questions &amp; Answers help to build your confidence during interview and crack it easily. This is a collection of trending interview questions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-12T11:48:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-03T10:55:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/C-Programming-Interview-Question.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ Interview Questions &amp; Answers (Prepared by Industry Experts) - DataFlair","description":"C++ Interview Questions & Answers help to build your confidence during interview and crack it easily. This is a collection of trending interview questions","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:\/\/data-flair.training\/blogs\/cpp-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"C++ Interview Questions &amp; Answers (Prepared by Industry Experts) - DataFlair","og_description":"C++ Interview Questions & Answers help to build your confidence during interview and crack it easily. This is a collection of trending interview questions","og_url":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-07-12T11:48:13+00:00","article_modified_time":"2020-02-03T10:55:28+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/C-Programming-Interview-Question.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"C++ Interview Questions &amp; Answers (Prepared by Industry Experts)","datePublished":"2019-07-12T11:48:13+00:00","dateModified":"2020-02-03T10:55:28+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/"},"wordCount":1622,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/C-Programming-Interview-Question.jpg","keywords":["Best C++ Interview Questions","c coding interview questions","C Interview Questions for experienced","C Interview Questions for freshers","C++ Interview Questions","C++ Programming Interview Questions","Latest C Interview Questions","Top c interview questions"],"articleSection":["C++ Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/","url":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/","name":"C++ Interview Questions &amp; Answers (Prepared by Industry Experts) - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/C-Programming-Interview-Question.jpg","datePublished":"2019-07-12T11:48:13+00:00","dateModified":"2020-02-03T10:55:28+00:00","description":"C++ Interview Questions & Answers help to build your confidence during interview and crack it easily. This is a collection of trending interview questions","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/C-Programming-Interview-Question.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/C-Programming-Interview-Question.jpg","width":802,"height":420,"caption":"C++ Programming Interview Question"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/cpp-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"C++ Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/cpp\/"},{"@type":"ListItem","position":3,"name":"C++ Interview Questions &amp; Answers (Prepared by Industry Experts)"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/61878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=61878"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/61878\/revisions"}],"predecessor-version":[{"id":63047,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/61878\/revisions\/63047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/63032"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=61878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=61878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=61878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}