{"id":46473,"date":"2019-02-14T03:20:51","date_gmt":"2019-02-14T03:20:51","guid":{"rendered":"https:\/\/www.softwaretestinghelp.com\/?page_id=46473"},"modified":"2026-02-20T14:25:31","modified_gmt":"2026-02-20T14:25:31","slug":"cpp-interview-questions","status":"publish","type":"page","link":"https:\/\/www.softwaretestinghelp.com\/cpp-interview-questions\/","title":{"rendered":"TOP 70 C++ Interview Questions and Answers [Includes Advanced]"},"content":{"rendered":"\n<p><strong>Most frequently asked basic and advanced C++ interview questions with code examples for entry-level candidates and experienced professionals:<\/strong><\/p>\n\n\n\n<p>This detailed article will undoubtedly be a valuable resource for those preparing for a C++ interview.<\/p>\n\n\n\n<p>Almost all major topics in C++ are covered here, along with some basic questions on advanced topics such as the Standard Template Library (STL).<\/p>\n\n\n\n<p>This set of C++ coding questions will help you face any C++ interview confidently and clear it successfully on your first attempt.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Quiz on C++ Interview Questions<\/h2>\n\n\n\n<p>Try this expert challenge on C++ Interview Questions and get placed in the Top MNCs of your choice. This curated list of hand-picked interview questions will help you face any interview confidently.<\/p>\n\n\n\n<div id=\"cpp-quiz-container\" style=\"max-width: 800px; margin: 0 auto; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #8B0000 0%, #DC143C 50%, #B22222 100%); border-radius: 20px; box-shadow: 0 20px 40px rgba(0,0,0,0.3); overflow: hidden; position: relative;\">\n  <style>\n    #cpp-quiz-container * {\n      box-sizing: border-box;\n    }\n    \n    .quiz-header {\n      text-align: center;\n      padding: 30px 20px 20px;\n      background: rgba(255,255,255,0.1);\n      backdrop-filter: blur(10px);\n      border-bottom: 1px solid rgba(255,255,255,0.2);\n    }\n    \n    .quiz-title {\n      font-size: 2.5rem;\n      font-weight: 700;\n      color: white;\n      margin: 0 0 10px;\n      text-shadow: 2px 2px 4px rgba(0,0,0,0.3);\n    }\n    \n    .quiz-subtitle {\n      font-size: 1.2rem;\n      color: rgba(255,255,255,0.9);\n      margin: 0;\n      font-weight: 300;\n    }\n    \n    .progress-container {\n      padding: 20px;\n      background: rgba(255,255,255,0.05);\n    }\n    \n    .progress-bar {\n      width: 100%;\n      height: 8px;\n      background: rgba(255,255,255,0.2);\n      border-radius: 4px;\n      overflow: hidden;\n      margin-bottom: 10px;\n    }\n    \n    .progress-fill {\n      height: 100%;\n      background: linear-gradient(90deg, #FFD700, #FFA500);\n      border-radius: 4px;\n      transition: width 0.3s ease;\n      width: 0%;\n    }\n    \n    .progress-text {\n      color: white;\n      font-size: 0.9rem;\n      text-align: center;\n    }\n    \n    .question-container {\n      padding: 30px;\n      background: rgba(255,255,255,0.95);\n      margin: 20px;\n      border-radius: 15px;\n      backdrop-filter: blur(10px);\n      box-shadow: 0 10px 30px rgba(0,0,0,0.2);\n      min-height: 400px;\n    }\n    \n    .question-category {\n      display: inline-block;\n      padding: 6px 12px;\n      border-radius: 20px;\n      font-size: 0.8rem;\n      font-weight: 600;\n      margin-bottom: 15px;\n      text-transform: uppercase;\n      letter-spacing: 0.5px;\n    }\n    \n    .category-basic {\n      background: linear-gradient(45deg, #4CAF50, #8BC34A);\n      color: white;\n    }\n    \n    .category-intermediate {\n      background: linear-gradient(45deg, #FF9800, #FFC107);\n      color: white;\n    }\n    \n    .category-advanced {\n      background: linear-gradient(45deg, #9C27B0, #E91E63);\n      color: white;\n    }\n    \n    .question-text {\n      font-size: 1.3rem;\n      color: #333;\n      margin-bottom: 25px;\n      line-height: 1.5;\n      font-weight: 500;\n    }\n    \n    .answer-option {\n      background: linear-gradient(135deg, #f8f9fa, #e9ecef);\n      border: 2px solid #dee2e6;\n      border-radius: 10px;\n      padding: 15px 20px;\n      margin: 10px 0;\n      cursor: pointer;\n      transition: all 0.3s ease;\n      position: relative;\n      overflow: hidden;\n    }\n    \n    .answer-option:hover {\n      background: linear-gradient(135deg, #e9ecef, #dee2e6);\n      border-color: #8B0000;\n      transform: translateY(-2px);\n      box-shadow: 0 5px 15px rgba(139,0,0,0.2);\n    }\n    \n    .answer-option.correct {\n      background: linear-gradient(135deg, #d4edda, #c3e6cb);\n      border-color: #28a745;\n      animation: correctPulse 0.6s ease;\n    }\n    \n    .answer-option.incorrect {\n      background: linear-gradient(135deg, #f8d7da, #f5c6cb);\n      border-color: #dc3545;\n      animation: incorrectShake 0.6s ease;\n    }\n    \n    .answer-option.disabled {\n      pointer-events: none;\n      opacity: 0.7;\n    }\n    \n    @keyframes correctPulse {\n      0%, 100% { transform: scale(1); }\n      50% { transform: scale(1.02); }\n    }\n    \n    @keyframes incorrectShake {\n      0%, 100% { transform: translateX(0); }\n      25% { transform: translateX(-5px); }\n      75% { transform: translateX(5px); }\n    }\n    \n    .feedback {\n      margin-top: 20px;\n      padding: 15px;\n      border-radius: 8px;\n      font-size: 1rem;\n      line-height: 1.5;\n    }\n    \n    .feedback.correct {\n      background: linear-gradient(135deg, #d4edda, #c3e6cb);\n      color: #155724;\n      border-left: 4px solid #28a745;\n    }\n    \n    .feedback.incorrect {\n      background: linear-gradient(135deg, #f8d7da, #f5c6cb);\n      color: #721c24;\n      border-left: 4px solid #dc3545;\n    }\n    \n    .next-button {\n      background: linear-gradient(135deg, #8B0000, #DC143C);\n      color: white;\n      border: none;\n      padding: 12px 30px;\n      border-radius: 25px;\n      font-size: 1rem;\n      font-weight: 600;\n      cursor: pointer;\n      margin: 20px auto 0;\n      display: block;\n      transition: all 0.3s ease;\n      box-shadow: 0 4px 15px rgba(139,0,0,0.3);\n    }\n    \n    .next-button:hover {\n      transform: translateY(-2px);\n      box-shadow: 0 6px 20px rgba(139,0,0,0.4);\n    }\n    \n    .next-button:disabled {\n      opacity: 0.6;\n      cursor: not-allowed;\n      transform: none;\n    }\n    \n    .results-container {\n      text-align: center;\n      padding: 40px 30px;\n      color: white;\n    }\n    \n    .score-circle {\n      width: 150px;\n      height: 150px;\n      border-radius: 50%;\n      background: linear-gradient(135deg, #FFD700, #FFA500);\n      display: flex;\n      align-items: center;\n      justify-content: center;\n      margin: 0 auto 30px;\n      box-shadow: 0 10px 30px rgba(0,0,0,0.3);\n      animation: scoreAppear 0.8s ease;\n    }\n    \n    @keyframes scoreAppear {\n      0% { transform: scale(0) rotate(180deg); opacity: 0; }\n      100% { transform: scale(1) rotate(0deg); opacity: 1; }\n    }\n    \n    .score-text {\n      font-size: 2.5rem;\n      font-weight: 700;\n      color: #8B0000;\n    }\n    \n    .results-title {\n      font-size: 2rem;\n      margin-bottom: 20px;\n      font-weight: 600;\n    }\n    \n    .results-message {\n      font-size: 1.2rem;\n      margin-bottom: 30px;\n      line-height: 1.6;\n    }\n    \n    .study-suggestions {\n      background: rgba(255,255,255,0.1);\n      border-radius: 15px;\n      padding: 20px;\n      margin-top: 30px;\n      text-align: left;\n      backdrop-filter: blur(10px);\n    }\n    \n    .restart-button {\n      background: linear-gradient(135deg, #FFD700, #FFA500);\n      color: #8B0000;\n      border: none;\n      padding: 15px 40px;\n      border-radius: 25px;\n      font-size: 1.1rem;\n      font-weight: 600;\n      cursor: pointer;\n      margin-top: 30px;\n      transition: all 0.3s ease;\n      box-shadow: 0 4px 15px rgba(255,215,0,0.3);\n    }\n    \n    .restart-button:hover {\n      transform: translateY(-2px);\n      box-shadow: 0 6px 20px rgba(255,215,0,0.4);\n    }\n    \n    .encouragement {\n      position: absolute;\n      top: 20px;\n      right: 20px;\n      background: rgba(255,255,255,0.9);\n      color: #8B0000;\n      padding: 8px 16px;\n      border-radius: 20px;\n      font-size: 0.9rem;\n      font-weight: 600;\n      animation: fadeInOut 3s ease;\n    }\n    \n    @keyframes fadeInOut {\n      0%, 100% { opacity: 0; transform: translateY(-10px); }\n      20%, 80% { opacity: 1; transform: translateY(0); }\n    }\n    \n    .code-block {\n      background: #1e1e1e;\n      color: #d4d4d4;\n      padding: 15px;\n      border-radius: 8px;\n      font-family: 'Consolas', 'Monaco', 'Courier New', monospace;\n      font-size: 14px;\n      line-height: 1.4;\n      margin: 10px 0;\n      overflow-x: auto;\n      border-left: 4px solid #007ACC;\n    }\n    \n    .keyword { color: #569cd6; font-weight: bold; }\n    .string { color: #ce9178; }\n    .comment { color: #6a9955; font-style: italic; }\n    .number { color: #b5cea8; }\n    .operator { color: #d4d4d4; }\n    .preprocessor { color: #9cdcfe; }\n    .function { color: #dcdcaa; }\n    .type { color: #4ec9b0; }\n    .variable { color: #9cdcfe; }\n    \n    @media (max-width: 768px) {\n      .quiz-title { font-size: 2rem; }\n      .quiz-subtitle { font-size: 1rem; }\n      .question-text { font-size: 1.1rem; }\n      .question-container { padding: 20px; margin: 15px; }\n      .answer-option { padding: 12px 15px; }\n      .code-block { font-size: 12px; padding: 10px; }\n    }\n  <\/style>\n\n  <div class=\"quiz-header\">\n    <div class=\"quiz-title\">C++ Interview Questions QUIZ<\/div>\n    <div class=\"quiz-subtitle\">Master C++ Programming &#038; Land Your Dream Job \ud83d\udcbb<\/div>\n  <\/div>\n\n  <div class=\"progress-container\">\n    <div class=\"progress-bar\">\n      <div class=\"progress-fill\" id=\"progressBar\"><\/div>\n    <\/div>\n    <div class=\"progress-text\" id=\"progressText\">Question 1 of 15<\/div>\n  <\/div>\n\n  <div id=\"quizContent\"><\/div>\n\n  <script>\n    (function() {\n      const questionBank = [\n        {\n          category: \"Basic\",\n          question: \"What will this C++ code output?\\n\\n<div class='code-block'><span class='preprocessor'>#include<\/span> <span class='string'>&lt;iostream&gt;<\/span><br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span> <span class='variable'>i<\/span> <span class='operator'>=<\/span> <span class='number'>5<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='operator'>++<\/span><span class='variable'>i<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='string'>\\\" \\\"<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>i<\/span><span class='operator'>++<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"6 6\",\n            \"6 5\",\n            \"5 5\",\n            \"Compilation error\"\n          ],\n          correct: 1,\n          explanation: \"++i increments first then returns 6, i++ returns current value (5) then increments. Final output: 6 5.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"Which of the following correctly declares a pointer in C++?\",\n          options: [\n            \"int ptr;\",\n            \"int* ptr;\",\n            \"pointer int ptr; with additional memory allocation specifications\",\n            \"int &ptr;\"\n          ],\n          correct: 1,\n          explanation: \"int* ptr; declares a pointer to an integer. The asterisk (*) indicates it's a pointer type, while & declares a reference.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What's wrong with this C++ code?\\n\\n<div class='code-block'><span class='type'>int<\/span><span class='operator'>*<\/span> <span class='function'>createArray<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span> <span class='variable'>arr<\/span>[<span class='number'>5<\/span>] <span class='operator'>=<\/span> {<span class='number'>1<\/span>, <span class='number'>2<\/span>, <span class='number'>3<\/span>, <span class='number'>4<\/span>, <span class='number'>5<\/span>};<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='variable'>arr<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"Nothing wrong, it works perfectly for all use cases\",\n            \"Returning pointer to local array that will be destroyed\",\n            \"Array size should be larger for better performance optimization\",\n            \"Missing include statement\"\n          ],\n          correct: 1,\n          explanation: \"The function returns a pointer to a local array that gets destroyed when the function ends, leading to undefined behavior.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What is the difference between a class and a struct in C++?\",\n          options: [\n            \"Classes use dynamic memory, structs use static memory allocation\",\n            \"Default access level: class members are private, struct members are public\",\n            \"Classes support inheritance, structs don't support object-oriented features\",\n            \"Structs are deprecated in modern C++ development practices\"\n          ],\n          correct: 1,\n          explanation: \"The main difference is default access: class members are private by default, while struct members are public by default.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What will this code print?\\n\\n<div class='code-block'><span class='preprocessor'>#include<\/span> <span class='string'>&lt;iostream&gt;<\/span><br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span> <span class='variable'>x<\/span> <span class='operator'>=<\/span> <span class='number'>10<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span><span class='operator'>*<\/span> <span class='variable'>ptr<\/span> <span class='operator'>=<\/span> <span class='operator'>&<\/span><span class='variable'>x<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='operator'>*<\/span><span class='variable'>ptr<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"Memory address of x\",\n            \"10\",\n            \"Compilation error occurs during build process\",\n            \"Undefined behavior\"\n          ],\n          correct: 1,\n          explanation: \"*ptr dereferences the pointer to get the value stored at the memory location, which is 10.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What's the output of this inheritance example?\\n\\n<div class='code-block'><span class='keyword'>class<\/span> <span class='type'>Base<\/span> {<br\/><span class='keyword'>public<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>virtual<\/span> <span class='type'>void<\/span> <span class='function'>show<\/span>() { <span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='string'>\\\"Base\\\"<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>; }<br\/>};<br\/><span class='keyword'>class<\/span> <span class='type'>Derived<\/span> : <span class='keyword'>public<\/span> <span class='type'>Base<\/span> {<br\/><span class='keyword'>public<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>void<\/span> <span class='function'>show<\/span>() <span class='keyword'>override<\/span> { <span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='string'>\\\"Derived\\\"<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>; }<br\/>};<br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>Base<\/span><span class='operator'>*<\/span> <span class='variable'>ptr<\/span> <span class='operator'>=<\/span> <span class='keyword'>new<\/span> <span class='type'>Derived<\/span>();<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>ptr<\/span><span class='operator'>-&gt;<\/span><span class='function'>show<\/span>();<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"Base\",\n            \"Derived\",\n            \"Compilation error with virtual function resolution issues\",\n            \"Both Base and Derived\"\n          ],\n          correct: 1,\n          explanation: \"Due to virtual function and runtime polymorphism, the Derived class's show() method is called, printing 'Derived'.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What is polymorphism in C++?\",\n          options: [\n            \"Having multiple constructors with different parameter sets and initialization logic\",\n            \"Objects of different types responding to the same interface\",\n            \"Creating multiple inheritance hierarchies with complex class relationships\",\n            \"Memory management techniques\"\n          ],\n          correct: 1,\n          explanation: \"Polymorphism allows objects of different types to be treated through a common interface, enabling dynamic behavior at runtime.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What will happen when this code runs?\\n\\n<div class='code-block'><span class='variable'>std<\/span>::<span class='type'>vector<\/span>&lt;<span class='type'>int<\/span>&gt; <span class='variable'>vec<\/span> <span class='operator'>=<\/span> {<span class='number'>1<\/span>, <span class='number'>2<\/span>, <span class='number'>3<\/span>, <span class='number'>4<\/span>, <span class='number'>5<\/span>};<br\/><span class='keyword'>for<\/span> (<span class='keyword'>auto<\/span> <span class='variable'>it<\/span> <span class='operator'>=<\/span> <span class='variable'>vec<\/span>.<span class='function'>begin<\/span>(); <span class='variable'>it<\/span> <span class='operator'>!=<\/span> <span class='variable'>vec<\/span>.<span class='function'>end<\/span>(); <span class='operator'>++<\/span><span class='variable'>it<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>if<\/span> (<span class='operator'>*<\/span><span class='variable'>it<\/span> <span class='operator'>==<\/span> <span class='number'>3<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>vec<\/span>.<span class='function'>erase<\/span>(<span class='variable'>it<\/span>);<br\/>&nbsp;&nbsp;&nbsp;&nbsp;}<br\/>}<\/div>\",\n          options: [\n            \"Successfully removes element 3 from vector without any issues\",\n            \"Iterator invalidation causing undefined behavior\",\n            \"Compilation error due to incorrect iterator usage syntax\",\n            \"Performance warning but works correctly\"\n          ],\n          correct: 1,\n          explanation: \"After erasing an element, the iterator becomes invalid. The correct approach is to use the return value of erase().\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What is a virtual function in C++?\",\n          options: [\n            \"A function that doesn't exist in memory but is simulated during execution\",\n            \"A function that enables runtime polymorphism\",\n            \"A template function with generic parameters and automatic type deduction\",\n            \"A static function with class-level scope and shared memory allocation\"\n          ],\n          correct: 1,\n          explanation: \"Virtual functions enable runtime polymorphism by allowing derived classes to override base class functions with dynamic dispatch.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What's the issue with this constructor?\\n\\n<div class='code-block'><span class='keyword'>class<\/span> <span class='type'>MyClass<\/span> {<br\/><span class='keyword'>private<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span><span class='operator'>*<\/span> <span class='variable'>data<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span> <span class='variable'>size<\/span>;<br\/><span class='keyword'>public<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='function'>MyClass<\/span>(<span class='type'>int<\/span> <span class='variable'>s<\/span>) : <span class='variable'>size<\/span>(<span class='variable'>s<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>data<\/span> <span class='operator'>=<\/span> <span class='keyword'>new<\/span> <span class='type'>int<\/span>[<span class='variable'>size<\/span>];<br\/>&nbsp;&nbsp;&nbsp;&nbsp;}<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='comment'>\/\/ No destructor, copy constructor, or assignment operator<\/span><br\/>};<\/div>\",\n          options: [\n            \"Missing proper resource management (Rule of Three\/Five)\",\n            \"Constructor parameters should be passed by reference for optimization\",\n            \"Private members should be protected for better inheritance support\",\n            \"Nothing wrong with this implementation\"\n          ],\n          correct: 0,\n          explanation: \"This class violates the Rule of Three\/Five by allocating memory without providing destructor, copy constructor, or assignment operator, leading to memory leaks and double deletion.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What does this template code accomplish?\\n\\n<div class='code-block'><span class='keyword'>template<\/span>&lt;<span class='keyword'>typename<\/span> <span class='type'>T<\/span>&gt;<br\/><span class='type'>T<\/span> <span class='function'>max<\/span>(<span class='type'>T<\/span> <span class='variable'>a<\/span>, <span class='type'>T<\/span> <span class='variable'>b<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> (<span class='variable'>a<\/span> <span class='operator'>&gt;<\/span> <span class='variable'>b<\/span>) <span class='operator'>?<\/span> <span class='variable'>a<\/span> <span class='operator'>:<\/span> <span class='variable'>b<\/span>;<br\/>}<br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='function'>max<\/span>(<span class='number'>10<\/span>, <span class='number'>20<\/span>) <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='function'>max<\/span>(<span class='number'>3.14<\/span>, <span class='number'>2.71<\/span>) <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"Creates a generic function that works with different data types\",\n            \"Only works with integer types due to template specialization constraints\",\n            \"Causes compilation errors due to type ambiguity and template resolution\",\n            \"Requires explicit type specification for each function call\"\n          ],\n          correct: 0,\n          explanation: \"This template function works with any type that supports the > operator, demonstrating generic programming in C++.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What is RAII (Resource Acquisition Is Initialization) in C++?\",\n          options: [\n            \"A memory optimization technique for reducing cache misses and improving performance\",\n            \"A design pattern where resource management is tied to object lifetime\",\n            \"A compiler optimization for automatic resource allocation and efficient memory usage\",\n            \"A debugging methodology for tracking resource usage and memory consumption\"\n          ],\n          correct: 1,\n          explanation: \"RAII ensures that resource acquisition happens during object construction and release happens during destruction, providing exception safety.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What's the benefit of this move constructor?\\n\\n<div class='code-block'><span class='keyword'>class<\/span> <span class='type'>MyString<\/span> {<br\/><span class='keyword'>private<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>char<\/span><span class='operator'>*<\/span> <span class='variable'>data<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>size_t<\/span> <span class='variable'>length<\/span>;<br\/><span class='keyword'>public<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='comment'>\/\/ Move constructor<\/span><br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='function'>MyString<\/span>(<span class='type'>MyString<\/span><span class='operator'>&&<\/span> <span class='variable'>other<\/span>) <span class='keyword'>noexcept<\/span> <br\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: <span class='variable'>data<\/span>(<span class='variable'>other<\/span>.<span class='variable'>data<\/span>), <span class='variable'>length<\/span>(<span class='variable'>other<\/span>.<span class='variable'>length<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>other<\/span>.<span class='variable'>data<\/span> <span class='operator'>=<\/span> <span class='keyword'>nullptr<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>other<\/span>.<span class='variable'>length<\/span> <span class='operator'>=<\/span> <span class='number'>0<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;}<br\/>};<\/div>\",\n          options: [\n            \"Transfers ownership without copying data, improving performance\",\n            \"Provides better debugging capabilities for string manipulation operations\",\n            \"Ensures thread safety in multi-threaded string processing environments\",\n            \"Only works with C-style strings, not std::string objects\"\n          ],\n          correct: 0,\n          explanation: \"Move constructors transfer ownership of resources instead of copying them, significantly improving performance for expensive-to-copy objects.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What will this smart pointer code do?\\n\\n<div class='code-block'><span class='variable'>std<\/span>::<span class='type'>unique_ptr<\/span>&lt;<span class='type'>int<\/span>&gt; <span class='variable'>ptr1<\/span> <span class='operator'>=<\/span> <span class='variable'>std<\/span>::<span class='function'>make_unique<\/span>&lt;<span class='type'>int<\/span>&gt;(<span class='number'>42<\/span>);<br\/><span class='variable'>std<\/span>::<span class='type'>unique_ptr<\/span>&lt;<span class='type'>int<\/span>&gt; <span class='variable'>ptr2<\/span> <span class='operator'>=<\/span> <span class='variable'>std<\/span>::<span class='function'>move<\/span>(<span class='variable'>ptr1<\/span>);<br\/><span class='keyword'>if<\/span> (<span class='variable'>ptr1<\/span> <span class='operator'>==<\/span> <span class='keyword'>nullptr<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='string'>\\\"ptr1 is null\\\"<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>}<br\/><span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='operator'>*<\/span><span class='variable'>ptr2<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<\/div>\",\n          options: [\n            \"Print 'ptr1 is null' and then 42\",\n            \"Compilation error due to unique_ptr move semantics violation\",\n            \"Both pointers will contain the same value causing undefined behavior\",\n            \"Memory leak occurs\"\n          ],\n          correct: 0,\n          explanation: \"std::move transfers ownership from ptr1 to ptr2. ptr1 becomes null, and ptr2 owns the resource containing value 42.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"You need to implement thread-safe code. Which C++11 feature would you use?\",\n          options: [\n            \"Manual mutex implementation with custom locking mechanisms and synchronization protocols\",\n            \"std::mutex and std::lock_guard\",\n            \"Global variables only\",\n            \"Function pointers exclusively\"\n          ],\n          correct: 1,\n          explanation: \"std::mutex provides thread synchronization, and std::lock_guard ensures RAII-style automatic unlocking to prevent deadlocks.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What is the scope resolution operator in C++?\",\n          options: [\n            \"::\",\n            \"->\",\n            \".\" ,\n            \"&\"\n          ],\n          correct: 0,\n          explanation: \"The scope resolution operator (::) is used to access global variables, namespace members, and static class members.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What will this code output?\\n\\n<div class='code-block'><span class='preprocessor'>#include<\/span> <span class='string'>&lt;iostream&gt;<\/span><br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span> <span class='variable'>arr<\/span>[] <span class='operator'>=<\/span> {<span class='number'>10<\/span>, <span class='number'>20<\/span>, <span class='number'>30<\/span>};<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='operator'>*<\/span>(<span class='variable'>arr<\/span> <span class='operator'>+<\/span> <span class='number'>1<\/span>) <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"10\",\n            \"20\",\n            \"Memory address of second element in array\",\n            \"Compilation error\"\n          ],\n          correct: 1,\n          explanation: \"*(arr + 1) is equivalent to arr[1], which accesses the second element of the array, printing 20.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What is the STL in C++?\",\n          options: [\n            \"Standard Template Library providing containers, algorithms, and iterators\",\n            \"System Template Language for low-level programming and hardware interface\",\n            \"Static Type Library for compile-time type checking and validation\",\n            \"String Template Language for text processing and manipulation operations\"\n          ],\n          correct: 0,\n          explanation: \"STL (Standard Template Library) provides generic containers, algorithms, and iterators that work together efficiently.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What's wrong with this copy constructor?\\n\\n<div class='code-block'><span class='keyword'>class<\/span> <span class='type'>MyClass<\/span> {<br\/><span class='keyword'>private<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span><span class='operator'>*<\/span> <span class='variable'>data<\/span>;<br\/><span class='keyword'>public<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='function'>MyClass<\/span>(<span class='keyword'>const<\/span> <span class='type'>MyClass<\/span><span class='operator'>&<\/span> <span class='variable'>other<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>data<\/span> <span class='operator'>=<\/span> <span class='variable'>other<\/span>.<span class='variable'>data<\/span>;  <span class='comment'>\/\/ Shallow copy<\/span><br\/>&nbsp;&nbsp;&nbsp;&nbsp;}<br\/>};<\/div>\",\n          options: [\n            \"Should perform deep copy instead of shallow copy\",\n            \"Parameter should be passed by value for better performance optimization\",\n            \"Constructor should be declared as explicit to prevent implicit conversions\",\n            \"Nothing wrong with this implementation for all use cases\"\n          ],\n          correct: 0,\n          explanation: \"This performs a shallow copy, leading to both objects pointing to the same memory. When one is destroyed, the other has a dangling pointer.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What is template specialization in C++?\",\n          options: [\n            \"Optimizing templates for better performance in specific use cases and scenarios\",\n            \"Providing specific implementations for particular template parameters\",\n            \"Creating templates that work only with predefined data types and class hierarchies\",\n            \"A deprecated feature replaced by modern C++ concepts and type constraints\"\n          ],\n          correct: 1,\n          explanation: \"Template specialization allows providing specific implementations for particular template arguments, enabling optimized or different behavior.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What will this destructor code demonstrate?\\n\\n<div class='code-block'><span class='keyword'>class<\/span> <span class='type'>Demo<\/span> {<br\/><span class='keyword'>public<\/span>:<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='function'>Demo<\/span>() { <span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='string'>\\\"Constructor\\\"<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>; }<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='operator'>~<\/span><span class='function'>Demo<\/span>() { <span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='string'>\\\"Destructor\\\"<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>; }<br\/>};<br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>Demo<\/span> <span class='variable'>obj<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"Only Constructor will be printed due to early program termination\",\n            \"Constructor then Destructor when object goes out of scope\",\n            \"Compilation error due to missing virtual destructor declaration\",\n            \"Destructor only\"\n          ],\n          correct: 1,\n          explanation: \"The constructor is called when the object is created, and the destructor is automatically called when the object goes out of scope.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What is the purpose of the 'virtual' destructor?\",\n          options: [\n            \"To optimize memory deallocation performance in complex inheritance hierarchies\",\n            \"To ensure proper cleanup in inheritance hierarchies\",\n            \"To create destructors that don't actually delete objects but mark them for cleanup\",\n            \"To prevent object destruction in multi-threaded environments\"\n          ],\n          correct: 1,\n          explanation: \"Virtual destructors ensure that the correct destructor is called for derived objects when deleting through base class pointers.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What does this lambda expression do?\\n\\n<div class='code-block'><span class='keyword'>auto<\/span> <span class='variable'>lambda<\/span> <span class='operator'>=<\/span> [](<span class='type'>int<\/span> <span class='variable'>a<\/span>, <span class='type'>int<\/span> <span class='variable'>b<\/span>) <span class='operator'>-&gt;<\/span> <span class='type'>int<\/span> {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='variable'>a<\/span> <span class='operator'>+<\/span> <span class='variable'>b<\/span>;<br\/>};<br\/><span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='function'>lambda<\/span>(<span class='number'>5<\/span>, <span class='number'>3<\/span>) <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<\/div>\",\n          options: [\n            \"Creates an anonymous function that adds two integers and prints 8\",\n            \"Defines a mathematical function for lambda calculus expressions\",\n            \"Creates a template function with automatic parameter deduction capabilities\",\n            \"Generates a macro for inline function calls with enhanced performance\"\n          ],\n          correct: 0,\n          explanation: \"This lambda expression creates an anonymous function that takes two integers, adds them, and returns the result. It will print 8.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"You're debugging a memory leak in production. What's your systematic approach?\",\n          options: [\n            \"Use memory profiling tools, review RAII patterns, check smart pointer usage\",\n            \"Restart the application periodically to clear memory and hope for the best\",\n            \"Add more memory to the system without addressing the underlying code issues\",\n            \"Ignore it unless users complain about performance degradation\"\n          ],\n          correct: 0,\n          explanation: \"Systematic debugging involves profiling tools (Valgrind, AddressSanitizer), reviewing resource management patterns, and ensuring proper RAII implementation.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"What will this reference code output?\\n\\n<div class='code-block'><span class='type'>void<\/span> <span class='function'>modifyValue<\/span>(<span class='type'>int<\/span><span class='operator'>&<\/span> <span class='variable'>ref<\/span>) {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>ref<\/span> <span class='operator'>=<\/span> <span class='number'>100<\/span>;<br\/>}<br\/><span class='type'>int<\/span> <span class='function'>main<\/span>() {<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>int<\/span> <span class='variable'>x<\/span> <span class='operator'>=<\/span> <span class='number'>50<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='function'>modifyValue<\/span>(<span class='variable'>x<\/span>);<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>std<\/span>::<span class='variable'>cout<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>x<\/span> <span class='operator'>&lt;&lt;<\/span> <span class='variable'>std<\/span>::<span class='variable'>endl<\/span>;<br\/>&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>return<\/span> <span class='number'>0<\/span>;<br\/>}<\/div>\",\n          options: [\n            \"50\",\n            \"100\",\n            \"Compilation error due to reference parameter modification\",\n            \"Undefined behavior\"\n          ],\n          correct: 1,\n          explanation: \"Pass by reference allows the function to modify the original variable directly. The function changes x to 100.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What is template metaprogramming in C++?\",\n          options: [\n            \"Using templates to perform computations at compile-time rather than runtime\",\n            \"A debugging technique for analyzing template instantiation and compilation errors\",\n            \"Creating templates that generate other templates automatically during compilation\",\n            \"A performance optimization for reducing template compilation time and code size\"\n          ],\n          correct: 0,\n          explanation: \"Template metaprogramming uses templates to perform computations during compilation, enabling compile-time optimizations and type manipulation.\"\n        },\n        {\n          category: \"Basic\",\n          question: \"What's the difference between this malloc and new usage?\\n\\n<div class='code-block'><span class='comment'>\/\/ Method 1<\/span><br\/><span class='type'>int<\/span><span class='operator'>*<\/span> <span class='variable'>ptr1<\/span> <span class='operator'>=<\/span> (<span class='type'>int<\/span><span class='operator'>*<\/span>)<span class='function'>malloc<\/span>(<span class='keyword'>sizeof<\/span>(<span class='type'>int<\/span>));<br\/><span class='operator'>*<\/span><span class='variable'>ptr1<\/span> <span class='operator'>=<\/span> <span class='number'>42<\/span>;<br\/><span class='function'>free<\/span>(<span class='variable'>ptr1<\/span>);<br\/><br\/><span class='comment'>\/\/ Method 2<\/span><br\/><span class='type'>int<\/span><span class='operator'>*<\/span> <span class='variable'>ptr2<\/span> <span class='operator'>=<\/span> <span class='keyword'>new<\/span> <span class='type'>int<\/span>(<span class='number'>42<\/span>);<br\/><span class='keyword'>delete<\/span> <span class='variable'>ptr2<\/span>;<\/div>\",\n          options: [\n            \"malloc allocates memory, new allocates and calls constructors\",\n            \"new is faster than malloc for all memory allocation scenarios\",\n            \"malloc is type-safe, new is not type-safe for complex object creation\",\n            \"Both are identical in functionality\"\n          ],\n          correct: 0,\n          explanation: \"malloc only allocates raw memory, while new allocates memory and calls the appropriate constructor for object initialization.\"\n        },\n        {\n          category: \"Intermediate\",\n          question: \"You need to handle a team disagreement about coding standards. How would you approach this?\",\n          options: [\n            \"Impose your preferred style without discussion to maintain consistency\",\n            \"Facilitate discussion, establish team guidelines, focus on maintainability\",\n            \"Let everyone use their own style to avoid conflict and maintain team harmony\",\n            \"Ask management to decide without team input or technical consideration\"\n          ],\n          correct: 1,\n          explanation: \"Good technical leadership involves facilitating collaborative discussions, establishing agreed-upon standards, and focusing on code maintainability.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"What is the Rule of Three (or Five) in C++?\",\n          options: [\n            \"A coding style guideline for limiting function parameters to improve readability\",\n            \"If you need custom destructor, copy constructor, or assignment operator, you likely need all three\",\n            \"A performance optimization requiring three passes of compiler optimization\",\n            \"A debugging methodology using three-step verification and testing procedures\"\n          ],\n          correct: 1,\n          explanation: \"The Rule of Three states that if a class needs a custom destructor, copy constructor, or copy assignment operator, it likely needs all three for proper resource management.\"\n        },\n        {\n          category: \"Advanced\",\n          question: \"You're implementing a high-performance container. What factors would you consider?\",\n          options: [\n            \"Cache locality, memory layout, iterator invalidation, exception safety\",\n            \"Only memory usage to minimize footprint regardless of performance characteristics\",\n            \"Compatibility with legacy C code without considering modern C++ features\",\n            \"Visual appearance in debugging tools and development environment integration\"\n          ],\n          correct: 0,\n          explanation: \"High-performance containers require considering cache efficiency, memory layout, iterator stability, and strong exception safety guarantees.\"\n        }\n      ];\n\n      let currentQuestionIndex = 0;\n      let selectedQuestions = [];\n      let userAnswers = [];\n      let score = 0;\n      let currentAnswer = null;\n\n      function shuffleArray(array) {\n        const shuffled = [...array];\n        for (let i = shuffled.length - 1; i > 0; i--) {\n          const j = Math.floor(Math.random() * (i + 1));\n          [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];\n        }\n        return shuffled;\n      }\n\n      function selectRandomQuestions() {\n        const shuffled = shuffleArray(questionBank);\n        selectedQuestions = shuffled.slice(0, 15);\n        \n        selectedQuestions.forEach(question => {\n          const correctAnswer = question.options[question.correct];\n          \/\/ Don't shuffle if \"All of the above\" is the correct answer\n          if (correctAnswer !== \"All of the above\") {\n            question.options = shuffleArray(question.options);\n            question.correct = question.options.indexOf(correctAnswer);\n          }\n        });\n      }\n\n      function updateProgress() {\n        const progressBar = document.getElementById('progressBar');\n        const progressText = document.getElementById('progressText');\n        const progress = ((currentQuestionIndex + 1) \/ selectedQuestions.length) * 100;\n        \n        progressBar.style.width = progress + '%';\n        progressText.textContent = `Question ${currentQuestionIndex + 1} of ${selectedQuestions.length}`;\n      }\n\n      function showEncouragement(isCorrect) {\n        const container = document.getElementById('cpp-quiz-container');\n        const existing = container.querySelector('.encouragement');\n        if (existing) existing.remove();\n\n        \/\/ Don't show encouragement on the first question\n        if (currentQuestionIndex > 0) {\n          const encouragement = document.createElement('div');\n          encouragement.className = 'encouragement';\n          \n          const messages = isCorrect \n            ? [\"\ud83c\udf89 Amazing!\", \"\u2728 Brilliant!\", \"\ud83d\ude80 Fantastic!\", \"\ud83d\udcaa Keep going!\", \"\ud83c\udf1f Excellent!\"]\n            : [\"\ud83d\udca1 Learning!\", \"\ud83c\udfaf Almost there!\", \"\ud83d\udcda Good try!\", \"\ud83d\udd25 Keep practicing!\", \"\u2b50 You're improving!\"];\n          \n          encouragement.textContent = messages[Math.floor(Math.random() * messages.length)];\n          container.appendChild(encouragement);\n          \n          setTimeout(() => encouragement.remove(), 3000);\n        }\n      }\n\n      function displayQuestion() {\n        if (currentQuestionIndex >= selectedQuestions.length) {\n          showResults();\n          return;\n        }\n\n        updateProgress();\n        \n        const question = selectedQuestions[currentQuestionIndex];\n        const quizContent = document.getElementById('quizContent');\n        const isLastQuestion = currentQuestionIndex === selectedQuestions.length - 1;\n        const buttonText = isLastQuestion ? \"View Results \ud83d\udcca\" : \"Next Question \u2192\";\n        \n        quizContent.innerHTML = `\n          <div class=\"question-container\">\n            <div class=\"question-category category-${question.category.toLowerCase()}\">${question.category} Questions<\/div>\n            <div class=\"question-text\">${question.question}<\/div>\n            <div class=\"options-container\">\n              ${question.options.map((option, index) => `\n                <div class=\"answer-option\" onclick=\"selectAnswer(${index})\">\n                  ${option}\n                <\/div>\n              `).join('')}\n            <\/div>\n            <div id=\"feedback\" style=\"display: none;\"><\/div>\n            <div id=\"encouragingMessage\" style=\"display: none; text-align: center; margin: 15px 0; padding: 12px 20px; font-weight: 600; color: #8B0000; font-size: 1.1rem; background: linear-gradient(135deg, #FFE4E1, #FFF0F5); border-radius: 10px; border: 1px solid #FFB6C1; box-shadow: 0 2px 8px rgba(139,0,0,0.1);\"><\/div>\n            <button id=\"nextButton\" class=\"next-button\" onclick=\"nextQuestion()\" style=\"display: none;\">\n              ${buttonText}\n            <\/button>\n          <\/div>\n        `;\n        \n        currentAnswer = null;\n      }\n\n      function selectAnswer(answerIndex) {\n        if (currentAnswer !== null) return;\n        \n        currentAnswer = answerIndex;\n        const question = selectedQuestions[currentQuestionIndex];\n        const options = document.querySelectorAll('.answer-option');\n        const feedback = document.getElementById('feedback');\n        const encouragingMessage = document.getElementById('encouragingMessage');\n        const nextButton = document.getElementById('nextButton');\n        \n        options.forEach(option => option.classList.add('disabled'));\n        \n        const isCorrect = answerIndex === question.correct;\n        \n        \/\/ Clean explanation text by removing initial congratulatory phrases\n        let cleanExplanation = question.explanation;\n        cleanExplanation = cleanExplanation.replace(\/^(\ud83c\udfaf|\u2728|\ud83c\udf1f|\ud83d\udd25|\ud83d\udca1|\u26a1|\ud83d\ude80|\ud83d\udc8e|\ud83d\udcf1|\ud83c\udfd7\ufe0f|\ud83d\udcab|\u2b50)\\s*(Correct|Perfect|Excellent|Great|Outstanding|Brilliant|Amazing|Fantastic|Spot on)!\\s*\/i, '');\n        \n        if (isCorrect) {\n          options[answerIndex].classList.add('correct');\n          score++;\n          feedback.className = 'feedback correct';\n          const correctPhrases = [\n            \"You're correct!\",\n            \"Exactly right!\",\n            \"Perfect answer!\",\n            \"Spot on!\",\n            \"Well done!\",\n            \"That's right!\",\n            \"Excellent choice!\",\n            \"Absolutely correct!\"\n          ];\n          const randomCorrectPhrase = correctPhrases[Math.floor(Math.random() * correctPhrases.length)];\n          feedback.innerHTML = `\u2705 <strong>${randomCorrectPhrase}<\/strong> ${cleanExplanation}`;\n        } else {\n          options[answerIndex].classList.add('incorrect');\n          options[question.correct].classList.add('correct');\n          feedback.className = 'feedback incorrect';\n          const incorrectPhrases = [\n            \"Almost there!\",\n            \"Good try!\",\n            \"Not quite right!\",\n            \"Close, but not exactly!\",\n            \"Nice attempt!\",\n            \"You're on the right track!\",\n            \"Keep thinking!\",\n            \"Good effort!\"\n          ];\n          const randomIncorrectPhrase = incorrectPhrases[Math.floor(Math.random() * incorrectPhrases.length)];\n          feedback.innerHTML = `\u274c <strong>${randomIncorrectPhrase}<\/strong> ${cleanExplanation}`;\n        }\n        \n        \/\/ Show encouraging message in separate section (only after first question)\n        if (currentQuestionIndex > 0) {\n          const encouragingPhrases = isCorrect \n            ? [\"You're doing absolutely great!\", \"Keep up the excellent work!\", \"Fantastic progress so far!\", \"You're really on fire!\", \"Amazing work, keep going!\", \"You're mastering this well!\", \"Excellent job, stay focused!\"]\n            : [\"You're learning so well!\", \"Keep going, you've got this!\", \"Almost there, don't stop!\", \"Good effort, keep trying!\", \"Don't give up, you're improving!\", \"Learning takes time, persist!\", \"Every mistake helps you grow!\"];\n          encouragingMessage.textContent = encouragingPhrases[Math.floor(Math.random() * encouragingPhrases.length)];\n          encouragingMessage.style.display = 'block';\n        }\n        \n        showEncouragement(isCorrect);\n        feedback.style.display = 'block';\n        nextButton.style.display = 'block';\n        \n        userAnswers.push({\n          question: question.question,\n          userAnswer: question.options[answerIndex],\n          correctAnswer: question.options[question.correct],\n          isCorrect: isCorrect\n        });\n      }\n\n      function nextQuestion() {\n        currentQuestionIndex++;\n        displayQuestion();\n      }\n\n      function getScoreMessage(percentage) {\n        if (percentage >= 90) return \"\ud83c\udfc6 Outstanding! You're a C++ expert!\";\n        if (percentage >= 80) return \"\ud83c\udf1f Excellent work! Strong C++ knowledge!\";\n        if (percentage >= 70) return \"\ud83d\ude80 Great job! You understand C++ concepts well!\";\n        if (percentage >= 60) return \"\ud83d\udcaa Good foundation! Keep building your C++ skills!\";\n        return \"\ud83d\udcda Keep learning! C++ mastery comes with practice!\";\n      }\n\n      function getStudySuggestions(percentage) {\n        if (percentage >= 90) {\n          return \"Focus on advanced C++ topics like template metaprogramming, concurrency, performance optimization, and modern C++ standards (C++17\/20). Consider contributing to open-source C++ projects and exploring system programming.\";\n        }\n        if (percentage >= 70) {\n          return \"Review intermediate concepts like STL, smart pointers, RAII, and object-oriented design patterns. Practice implementing data structures and algorithms, and explore modern C++ features like move semantics and lambdas.\";\n        }\n        return \"Start with C++ fundamentals: syntax, pointers, basic OOP concepts, and memory management. Practice writing simple programs, understand the difference between stack and heap, and master basic STL containers.\";\n      }\n\n      function showResults() {\n        const percentage = Math.round((score \/ selectedQuestions.length) * 100);\n        const quizContent = document.getElementById('quizContent');\n        \n        quizContent.innerHTML = `\n          <div class=\"results-container\">\n            <div class=\"score-circle\">\n              <div class=\"score-text\">${score}\/${selectedQuestions.length}<\/div>\n            <\/div>\n            <div class=\"results-title\">${getScoreMessage(percentage)}<\/div>\n            <div class=\"results-message\">\n              You scored ${percentage}% on this C++ knowledge quiz! \n              ${percentage >= 80 ? \"You're well-prepared for C++ development roles!\" : \"Keep practicing and you'll improve quickly!\"}\n            <\/div>\n            <div class=\"study-suggestions\">\n              <div style=\"margin-top: 0; color: #FFD700; font-size: 1.3rem; font-weight: 600; margin-bottom: 15px;\">\ud83d\udcbb Next Steps for C++ Mastery:<\/div>\n              <p>${getStudySuggestions(percentage)}<\/p>\n              <p><strong>Remember:<\/strong> C++ is a powerful language that opens doors to system programming, game development, embedded systems, and high-performance applications. Keep coding and never stop learning! \ud83d\ude80<\/p>\n            <\/div>\n            <button class=\"restart-button\" onclick=\"restartQuiz()\">\n              Take Quiz Again \ud83d\udd04\n            <\/button>\n          <\/div>\n        `;\n      }\n\n      function restartQuiz() {\n        currentQuestionIndex = 0;\n        userAnswers = [];\n        score = 0;\n        currentAnswer = null;\n        selectRandomQuestions();\n        displayQuestion();\n      }\n\n      window.selectAnswer = selectAnswer;\n      window.nextQuestion = nextQuestion;\n      window.restartQuiz = restartQuiz;\n\n      selectRandomQuestions();\n      displayQuestion();\n    })();\n  <\/script>\n<\/div>\n\n\n\n<\/br >\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2022\/09\/C-INTERVIEW-QUESTIONS-AND-ANSWERS.png\"><img decoding=\"async\" width=\"701\" height=\"351\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2022\/09\/C-INTERVIEW-QUESTIONS-AND-ANSWERS.png\" alt=\"C++ INTERVIEW QUESTIONS AND ANSWERS\" class=\"wp-image-229417\" style=\"width:827px;height:auto\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2022\/09\/C-INTERVIEW-QUESTIONS-AND-ANSWERS.png 701w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2022\/09\/C-INTERVIEW-QUESTIONS-AND-ANSWERS-300x150.png 300w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ Interview Questions With Code Examples<\/h2>\n\n\n\n<p>Enlisted below are the most popular C++ programming interview questions that are answered by a C++ expert.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic C++<\/h3>\n\n\n\n<p><span style=\"color: #000000;\"><strong>Structure Of C++ Program<\/strong><\/span><\/p>\n\n\n\n<p><strong>Q #1) What is the basic structure of a C++ program?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong>&nbsp;The basic structure of a C++ program is shown below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream.h&gt;\nint main()\n{\n                cout&lt;&lt;\u201dHello,World!\u201d;\n                return 0;\n}\n<\/pre><\/div>\n\n\n<p>The first line that begins with \u201c<strong><em>#<\/em><\/strong>\u201d is a <strong>preprocessor directive<\/strong>. In this case, we are using <strong>include<\/strong> as a directive, which tells the compiler to include a header, while \u201c<strong>iostream.h<\/strong>\u201d will be used for basic input\/output later in the program.<\/p>\n\n\n\n<p>The next line is the \u201cmain\u201d function that returns an integer. The main function is the starting point of execution for any C++ program. Irrespective of its position in the source code file, the C++ compiler always executes the contents of the main function first.<\/p>\n\n\n\n<p>In the next line, we can see open curly braces that indicate the start of a block of code. After this, we see the programming instruction or the line of code that uses the count, which is the standard output stream (its definition is present in iostream.h).<\/p>\n\n\n\n<p>This output stream takes a string of characters and prints it to a standard output device. Here, it is \u201cHello, World!\u201d. Please note that each C++ instruction ends with a semicolon (;), which is very much necessary, and omitting it will result in compilation errors.<\/p>\n\n\n\n<p>Before closing the braces}, we see another line \u201creturn 0;\u201d. This is the return point to the main function.<\/p>\n\n\n\n<p>Every C++ program will have a basic structure as shown above, with a preprocessor directive, the main function declaration, followed by a block of code, and then a return point to the main function, which shows the successful execution of the program.<\/p>\n\n\n\n<p><strong>Q #2) What are the Comments in C++? <\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> Comments in C++ are simply a piece of source code ignored by the compiler. They are only helpful for a programmer to add a description or additional information about their source code.<\/p>\n\n\n\n<p><strong>In C++, there are two ways to add comments:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/\/single-line comment<\/li>\n\n\n\n<li>\/* block comment *\/<\/li>\n<\/ul>\n\n\n\n<p>The first type will discard everything after the compiler encounters \u201c\/\/\u201d. In the second type, the compiler discards everything between \u201c\/*\u201d and \u201c*\/\u201d.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #000000;\">Variables, Data Types, And Constants<\/span><\/h4>\n\n\n\n<p><strong>Q #3) Difference between Declaration and Definition of a variable.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The declaration of a variable is merely specifying the data type of a variable and the variable name. As a result of the declaration, we tell the compiler to reserve space for a variable in memory according to the data type specified.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nint Result;\nchar c;\nint a,b,c;\n<\/pre><\/div>\n\n\n<p>All the above are valid declarations. Also, note that because of the declaration, the value of the variable is undetermined.<\/p>\n\n\n\n<p>Whereas a definition is an implementation\/instantiation of the declared variable, where we tie up an appropriate value to the declared variable so that the linker will link references to the appropriate entities.<\/p>\n\n\n\n<p><strong>From the above example<\/strong>,<\/p>\n\n\n\n<p>Result = 10;<\/p>\n\n\n\n<p>C = \u2018A\u2019;<\/p>\n\n\n\n<p>These are valid definitions.<\/p>\n\n\n\n<p><strong>Q #4) Comment on the Local and Global scope of a variable.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The scope of a variable is defined as the extent of the program code within which the variable remains active, i.e., it can be declared, defined, or worked with.<\/p>\n\n\n\n<p><strong>There are two types of scope in C++:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Local Scope: <\/strong>A variable is said to have a local scope or is local when it is declared inside a code block. The variable remains active only inside the block and is not accessible outside the code block.<\/li>\n\n\n\n<li><strong>Global Scope: <\/strong>A variable has a global scope when it is accessible throughout the program. You declare a global variable at the top of the program before all the function definitions.<\/li>\n<\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream.h&gt;\nInt globalResult=0; \/\/global variable\nint main()\n{\nInt localVar = 10; \/\/local variable.\n\u2026.. \n \n}\n<\/pre><\/div>\n\n\n<p><strong>Q #5) What is the precedence when there are a Global variable and a Local variable in the program with the same name?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Whenever there is a local variable with the same name as that of a global variable, the compiler gives precedence to the local variable.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream.h&gt;\n int globalVar = 2;\nint main()\n{\n int globalVar = 5;\n cout&lt;&lt;globalVar&lt;&lt;endl;\n}\n<\/pre><\/div>\n\n\n<p>The output of the above code is 5. This is because, although both the variables have the same name, the compiler has given preference to the local scope.<\/p>\n\n\n\n<p><strong>Q #6) When there are a Global variable and a Local variable with the same name, how will you access the global variable?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> When there are two variables with the same name but different scopes, i.e., one is a local variable, and the other is a global variable, the compiler will give preference to a local variable.<\/p>\n\n\n\n<p>To access the global variable, we make use of a \u201c<strong>scope resolution operator (::)<\/strong>\u201d. Using this operator, we can access the value of the global variable.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream.h&gt;\nint x= 10;\nint main()\n{\n int x= 2;\n cout&lt;&lt;\u201dGlobal Variable x = \u201c&lt;&lt;::x;\n cout&lt;&lt;\u201d\\nlocal Variable x= \u201c&lt;&lt;x;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Global Variable x = 10<br>local Variable x= 2<\/p>\n\n\n\n<p><strong>Q #7) How many ways are there to initialize an int with a Constant?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> <strong>There are two ways:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first format uses traditional C notation.<br>int result = 10;<\/li>\n\n\n\n<li>The second format uses the constructor notation.<br>int result (10);<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #000000;\">Constants<\/span><\/h4>\n\n\n\n<p><strong> Q #8) What is a Constant? Explain with an example.<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>A constant is an expression that has a fixed value. They can be divided into integer, decimal, floating-point, character, or string constants depending on their data type.<\/p>\n\n\n\n<p>Apart from the decimal, C++ also supports two more constants, i.e., octal (to the base 8) and hexadecimal (to the base 16) constants.<\/p>\n\n\n\n<p><strong>Examples of Constants:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>75 \/\/integer (decimal)<\/li>\n\n\n\n<li>0113 \/\/octal<\/li>\n\n\n\n<li>0x4b \/\/hexadecimal<\/li>\n\n\n\n<li>3.142 \/\/floating point<\/li>\n\n\n\n<li>\u2018c\u2019 \/\/character constant<\/li>\n\n\n\n<li>\u201cHello, World\u201d \/\/string constant<\/li>\n<\/ul>\n\n\n\n<p><strong>Note:<\/strong> When we have to represent a single character, we use single quotes, and when we want to define a constant with more than one character, we use double quotes.<\/p>\n\n\n\n<p><strong>Q #9) How do you define\/declare constants in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> In C++, we can define our own constants using the <strong>#define<\/strong> preprocessor directive.<\/p>\n\n\n\n<p><strong>#define Identifier value<\/strong><\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream.h&gt;\n#define PI 3.142\nint main ()\n{\n                 float radius =5, area;\n                 area = PI * r * r;\n                 cout&lt;&lt;\u201dArea of a Circle = \u201c&lt;&lt;area;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong> Area of a Circle = 78.55<\/p>\n\n\n\n<p>As shown in the above example, once we define a constant using the #define directive, we can use it throughout the program and substitute its value.<\/p>\n\n\n\n<p>We can declare constants in C++ using the \u201c<strong>const<\/strong>\u201d keyword. This way is similar to that of declaring a variable, but with a const prefix.<\/p>\n\n\n\n<p><strong>Examples of declaring a constant<\/strong><\/p>\n\n\n\n<p>const int pi = 3.142;<br>const char c = \u201csth\u201d;<br>const zipcode = 411014;<\/p>\n\n\n\n<p>In the above examples, whenever the type of constant is not specified, the C++ compiler defaults it to an integer type.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #000000;\">Operators<\/span><\/h4>\n\n\n\n<p><strong>Q #10) Comment on the Assignment Operator in C++.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The assignment operator in C++ is used to assign a value to another variable.<\/p>\n\n\n\n<p>a = 5;<\/p>\n\n\n\n<p>This line of code assigns the integer value <strong>5 <\/strong>to variable <strong>a<\/strong>.<\/p>\n\n\n\n<p>The part at the left of the =operator is known as an <strong>lvalue <\/strong>(left value) and the right as an <strong>rvalue<\/strong> (right value). <strong>Lvalue<\/strong> must always be a variable, whereas the right side can be a constant, a variable, the result of an operation, or any combination of them.<\/p>\n\n\n\n<p>The assignment operation always takes place from right to left and never in inverse.<\/p>\n\n\n\n<p>One property that C++ has over other programming languages is that the assignment operator can be used as the <em>rvalue <\/em>(or part of an <em>rvalue<\/em>) for another assignment.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>a = 2 + (b = 5);<\/p>\n\n\n\n<p>is equivalent to:<\/p>\n\n\n\n<p>b = 5;<br>a = 2 + b;<\/p>\n\n\n\n<p>This means, first assign <strong>5 <\/strong>to variable <strong>b <\/strong>and then assign to <strong>a, <\/strong>the value <strong>2 <\/strong>plus the result of the previous expression of <strong>b<\/strong> (that is 5), leaving <strong>a <\/strong>with a final value of <strong>7<\/strong>.<\/p>\n\n\n\n<p><strong>Thus, the following expression is also valid in C++:<\/strong><\/p>\n\n\n\n<p>a = b = c = 5;<\/p>\n\n\n\n<p>assign 5 to variables <strong>a<\/strong>, <strong>b, <\/strong>and <strong>c<\/strong>.<\/p>\n\n\n\n<p><strong>Q #11) What is the difference between equal to (==) and Assignment Operator (=)?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> In C++, equal to (==) and assignment operator (=) are two completely different operators.<\/p>\n\n\n\n<p>Equal to (==) is an equality relational operator that evaluates two expressions to see if they are equal and returns true if they are equal and false if they are not.<\/p>\n\n\n\n<p>The assignment operator (=) is used to assign a value to a variable. Hence, we can have a complex assignment operation inside the equality relational operator for evaluation.<\/p>\n\n\n\n<p><strong>Q #12)&nbsp;What are the various Arithmetic Operators in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;C++ supports the following arithmetic operators:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>+ addition<\/li>\n\n\n\n<li>&#8211; subtraction<\/li>\n\n\n\n<li>* multiplication<\/li>\n\n\n\n<li>\/ division<\/li>\n\n\n\n<li>% module<\/li>\n<\/ul>\n\n\n\n<p><strong>Let\u2019s demonstrate the various arithmetic operators with the following piece of code.<\/strong><\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream.h&gt;\nint main ()\n{\n              int a=5, b=3;\ncout&lt;&lt;\u201da + b = \u201c&lt;&lt;a+b;\ncout&lt;\u201d\\na \u2013 b =\u201d&lt;&lt;a-b;\ncout&lt;&lt;\u201d\\na * b =\u201d&lt;&lt;a*b;\ncout&lt;&lt;\u201d\\na \/ b =\u201d&lt;&lt;a\/b;\ncout&lt;&lt;\u201d\\na % b =\u201c&lt;&lt;a%b;\n \nreturn 0;\n }\n<\/pre><\/div>\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>a + b = 8<br>a \u2013 b =2<br>a * b =15<br>a \/ b =2<br>a % b=1<\/p>\n\n\n\n<p>As shown above, all the other operations are straightforward and the same as actual arithmetic operations, except the modulo operator, which is quite different. Modulo operator divides a and b, and the result of the operation is the remainder of the division.<\/p>\n\n\n\n<p><strong>Q #13) What are the various Compound Assignment Operators in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> <strong>The following are the Compound assignment operators in C++:<\/strong><\/p>\n\n\n\n<p><strong>+=, -=, *=, \/=, %=, &gt;&gt;=, &lt;&lt;=, &amp;=, ^=,|=<\/strong><\/p>\n\n\n\n<p>The compound assignment operator is one of the most important features of the C++ language, which allows us to change the value of a variable with one of the basic operators:<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvalue += increase; is equivalent to value = value + increase;\nif base_salary is a variable of type int.\n               int base_salary = 1000;\n               base_salary += 1000; #base_salary = base_salary + 1000\n               base_salary *= 5; #base_salary = base_salary * 5;\n<\/pre><\/div>\n\n\n<p><strong>Q #14) State the difference between Pre and Post Increment\/Decrement Operations.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> C++ allows two operators, i.e., ++ (increment) and&#8211; (decrement), that allow you to add 1 to the existing value of a variable and subtract 1 from the variable, respectively. These operators are, in turn, called increment (++) and decrement (&#8211;).<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>a=5;<br>a++;<\/p>\n\n\n\n<p>The second statement, a++, will cause 1 to be added to the value of a. Thus a++ is equivalent to<\/p>\n\n\n\n<p>a = a+1; or<br>a += 1;<\/p>\n\n\n\n<p>A unique feature of these operators is that we can prefix or suffix these operators with a variable. Hence, if a is a variable and we prefix the increment operator, it will be<\/p>\n\n\n\n<p>++a;<\/p>\n\n\n\n<p>This is called Pre-increment. Similarly, we have pre-decrement as well.<\/p>\n\n\n\n<p>If we prefix the variable a with an increment operator, we will have<\/p>\n\n\n\n<p>a++;<\/p>\n\n\n\n<p>This is the post-increment. Likewise, we have post-decrement too.<\/p>\n\n\n\n<p>The difference between the meaning of pre and post depends upon how the expression is evaluated, and the result is stored.<\/p>\n\n\n\n<p>In the case of the pre-increment\/decrement operator, the increment\/decrement operation is carried out first, and then the result is passed to an lvalue. Whereas for post-increment\/decrement operations, the lvalue is evaluated first and then increment\/decrement is performed accordingly.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>a = 5; b=6;<br>++a;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #a=6<br>b&#8211;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #b=6<br>&#8211;a;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #a=5<br>b++;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #6<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #000000;\">I\/O through Console<\/span><\/h4>\n\n\n\n<p><strong>Q #15) What are the Extraction and Insertion operators in C++? Explain with examples.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> In the iostream.h library of C++, <strong>cin<\/strong>, and <strong>cout<\/strong> are the two data streams that are used for input and output, respectively. Cout is normally directed to the screen, and cin is assigned to the keyboard.<\/p>\n\n\n\n<p><strong>\u201ccin\u201d (extraction operator):<\/strong> By using the overloaded operator &gt;&gt; with cin stream, C++ handles the standard input.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nint age;\ncin&gt;&gt;age;\n<\/pre><\/div>\n\n\n<p>As shown in the above example, an integer variable \u2018age\u2019 is declared, and then it waits for cin (keyboard) to enter the data. \u201ccin\u201d processes the input only when the RETURN key is pressed.<\/p>\n\n\n\n<p><strong>\u201ccout\u201d (insertion operator):<\/strong> This is used in conjunction with the overloaded &lt;&lt; operator. It directs the data that follows it into the cout stream.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\ncout&lt;&lt;\u201dHello, World!\u201d;\n cout&lt;&lt;123;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Control Structures And Functions<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Control Structures And Loops<\/h4>\n\n\n\n<p><strong>Q #16) What is the difference between a while and a do while loop? Explain with examples.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The format of the while loop in C++ is:<\/p>\n\n\n\n<p><strong> While (expression)<\/strong><br><strong> {statements;}<\/strong><\/p>\n\n\n\n<p>The statement block under while is executed as long as the condition in the given expression is true.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream.h&gt;\n int main()\n{\n               int n;\n               cout&lt;&lt;\u201dEnter the number : \u201c;\n               cin&gt;&gt;n;\n              while(n&gt;0)\n              {\n                              cout&lt;&lt;\u201d \u201c&lt;&lt;n;\n                              --n;\n              }\n              cout&lt;&lt;\u201dWhile loop complete\u201d;\n }\n<\/pre><\/div>\n\n\n<p>In the above code, the loop will directly exit if n is 0. Thus, in the while loop, the terminating condition is at the beginning of the loop and if it&#8217;s fulfilled, no iterations of the loop are executed.<\/p>\n\n\n\n<p>Next, we consider the do-while loop.<\/p>\n\n\n\n<p><strong>The general format of do-while is:<\/strong><\/p>\n\n\n\n<p><strong>do {statement;} while(condition);<\/strong><\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream.h&gt;\nint main()\n{\n               int n;\n               cout&lt;&lt;\u201dEnter the number : \u201c;\n               cin&gt;&gt;n;\n               do {\n                          cout&lt;&lt;n&lt;&lt;\u201d,\u201d;\n                          --n;\n                     }while(n&gt;0);\n                    cout&lt;&lt;\u201ddo-while complete\u201d;\n}\n<\/pre><\/div>\n\n\n<p>In the above code, we can see that the statement inside the loop is executed at least once as the loop condition is at the end. These are the main differences between the while and the do-while.<\/p>\n\n\n\n<p>In the case of the while loop, we can directly exit the loop at the beginning, if the condition is not met whereas in the do-while loop, we execute the loop statements at least once.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Functions<\/h4>\n\n\n\n<p><strong>Q #17) What do you mean by \u2018void\u2019 return type?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>All functions should return a value as per the general syntax.<\/p>\n\n\n\n<p>However, if we don&#8217;t want a function to return any value, we use \u201c<strong>void<\/strong>\u201d to indicate that. This means that we use \u201c<strong>void<\/strong>\u201d to indicate that the function has no return value or it returns \u201c<strong>void<\/strong>\u201d.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid myfunc()\n{\n                         Cout&lt;&lt;\u201dHello,This is my function!!\u201d;\n}\nint main()\n{\nmyfunc();\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<p><strong>Q #18) Explain Pass by Value and Pass by Reference.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> While passing parameters to the function using \u201cPass by Value\u201d, we pass a copy of the parameters to the function.<\/p>\n\n\n\n<p>Hence, whatever modifications are made to the parameters in the called function are not passed back to the calling function. Thus, the variables in the calling function remain unchanged.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid printFunc(int a,int b,int c)\n{\n                  a *=2;\n                  b *=2;\n                  c *=2;\n}\n\nint main()\n\n{\n\n                 int x = 1,y=3,z=4;\n                 printFunc(x,y,z);\n                 cout&lt;&lt;\u201dx = \u201c&lt;&lt;x&lt;&lt;\u201d\\ny = \u201c&lt;&lt;y&lt;&lt;\u201d\\nz = \u201c&lt;&lt;z;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<p>x=1<br>y=3<br>z=4<\/p>\n\n\n\n<p>As seen above, although the called function changed the parameters, the calling function did not reflect their values because the system passed them by value.<\/p>\n\n\n\n<p>However, if we want to get the changed values from the function back to the calling function, then we use the \u201cPass by Reference\u201d technique.<\/p>\n\n\n\n<p><strong>To demonstrate this, we modify the above program as follows:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid printFunc(int&amp; a,int&amp; b,int&amp; c)\n{\n                              a *=2;\n                              b *=2;\n                              c *=2;\n}\n  int main()\n{\n                  int x = 1,y=3,z=4;\n                  printFunc(x,y,z);\n                   cout&lt;&lt;\u201dx = \u201c&lt;&lt;x&lt;&lt;\u201d\\ny = \u201c&lt;&lt;y&lt;&lt;\u201d\\nz = \u201c&lt;&lt;z;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output: <\/strong><br>x=2<br>y=6<br>z=8<\/p>\n\n\n\n<p>As shown above, the modifications done to the parameters in the called functions are passed to the calling function when we use the \u201cPass by reference\u201d technique. This is because using this technique we do not pass a copy of the parameters, but we pass the variable\u2019s reference itself.<\/p>\n\n\n\n<p><strong>Q #19) What are Default Parameters? How are they evaluated in the C++ function?<\/strong><\/p>\n\n\n\n<p><strong>Answer: <\/strong>A default&nbsp;Parameter is a value that is assigned to each parameter while declaring a function.<\/p>\n\n\n\n<p>This value is used if that parameter is left blank while calling the function. To specify a default value for a particular parameter, we simply assign a value to the parameter in the function declaration.<\/p>\n\n\n\n<p>If the value is not passed for this parameter during the function call, then the compiler uses the default value provided. If a value is specified, then this default value is stepped on and the passed value is used.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nint multiply(int a, int b=2)\n{\n              int r;\n              r = a * b;\n              return r;\n} \n \nint main()\n {\n \n             Cout&lt;&lt;multiply(6);\n             Cout&lt;&lt;\u201d\\n\u201d;\n             Cout&lt;&lt;multiply(2,3);\n }\n<\/pre><\/div>\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<p>12<br>6<\/p>\n\n\n\n<p>As shown in the above code, there are two calls to the multiply function. In the first call, only one parameter is passed with a value. In this case, the second parameter is the default value provided. But in the second call, as both parameter values are passed, the default value is overridden and the passed value is used.<\/p>\n\n\n\n<p><strong>Q #20) What is an Inline function in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>An inline function is a function that is compiled by the compiler at the point of calling the function, and the code is substituted at that point. This makes compiling faster. This function is defined by prefixing the function prototype with the keyword \u201cinline\u201d.<\/p>\n\n\n\n<p>Such functions are advantageous only when the code of the inline function is small and simple. Although a function is defined as Inline, it is completely compiler-dependent to evaluate it as inline or not.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced-Data Structure<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Arrays<\/h4>\n\n\n\n<p><strong> Q #21) Why are arrays usually processed with a for loop?<\/strong><\/p>\n\n\n\n<p><strong class=\"\">Answer:&nbsp;An array<\/strong> uses the index to traverse each of its elements.<\/p>\n\n\n\n<p>If A is an array, then each of its elements is accessed as A[i]. Programmatically, all that is required for this to work is an iterative block with a loop variable i that serves as an index (counter) incrementing from 0 to A.length-1.<\/p>\n\n\n\n<p>This is exactly what a loop does, and this is the reason we process arrays using for loops.<\/p>\n\n\n\n<p><strong>Q #22)&nbsp;<\/strong><strong>State the difference between delete and delete[].<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> \u201cdelete[]\u201d is used to release the memory allocated to an array that was allocated using new[]. \u201cdelete\u201d is used to release one chunk of memory that was allocated using new.<\/p>\n\n\n\n<p><strong>Q #23) What is wrong with this code?<\/strong><\/p>\n\n\n\n<p><strong>T *p = new T[10];<\/strong><br><strong>delete p;<\/strong><\/p>\n\n\n\n<p><strong>Answer: <\/strong>The above code is syntactically correct and will compile fine.<\/p>\n\n\n\n<p>The only problem is that it will just delete the first element of the array. Though the entire array is deleted, only the destructor of the first element will be called, and the memory for the first element is released.<\/p>\n\n\n\n<p><strong>Q #24) What&#8217;s the order in which the objects in an array are destructed?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Objects in an array are destructed in the reverse order of construction: First constructed, last destructed.<\/p>\n\n\n\n<p><strong>In the following example,<\/strong> the order for destructors will be a[9], a[8], &#8230;, a[1], a[0]:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoiduserCode()\n{\n                 Car a&#x5B;10];\n                  ...\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">Pointers<\/h4>\n\n\n\n<p><strong>Q #25) What is wrong with this code?<\/strong><\/p>\n\n\n\n<p><strong>T *p = 0;<\/strong><br><strong>delete p;<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> In the above code, the pointer is null. Per the C++ 03 standard, it&#8217;s perfectly valid to call delete on a NULL pointer. The delete operator would take care of the NULL check internally.<\/p>\n\n\n\n<p><strong>Q #26) What is a Reference Variable in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>A reference variable is an alias name for the existing variable. This means that both the variable name and the reference variable point to the same memory location. Hence, whenever the variable is updated, the reference is updated too.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong>Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nint a=10;\n int& b = a;\n<\/pre><\/div>\n\n\n<p>Here, b is the reference of a.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Storage Classes<\/h4>\n\n\n\n<p><strong>Q #27) What is a Storage Class? Mention the Storage Classes in C++.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> Storage class determines the life or scope of symbols such as variables or functions.<\/p>\n\n\n\n<p><strong>C++ supports the following storage classes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Auto<\/li>\n\n\n\n<li>Static<\/li>\n\n\n\n<li>Extern<\/li>\n\n\n\n<li>Register<\/li>\n\n\n\n<li>Mutable<\/li>\n<\/ul>\n\n\n\n<p><strong>Q #28) Explain the Mutable Storage class specifier.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The variable of a constant class object\u2019s member cannot be changed. However, by declaring the variables as \u201cmutable\u201d, we can change the values of these variables.<\/p>\n\n\n\n<p><strong>Q #29) What is the keyword auto for?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> By default, every local variable of a function is automatic, i.e. <em>auto<\/em>. In the below function, both the variables \u2018i\u2019 and \u2018j\u2019 are automatic variables.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid f()\n {\n int i; \n auto int j;\n }\n<\/pre><\/div>\n\n\n<p><strong>NOTE<\/strong>: A global variable is not an automatic variable.<\/p>\n\n\n\n<p><strong>Q #30) What is a Static Variable?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> A static variable is a local variable that retains its value across function calls. Static variables are declared using the keyword \u201cstatic\u201d. Numeric variables that are static have the default value of zero.<\/p>\n\n\n\n<p><strong>The following function will print 1 2 3 if called thrice.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid f()\n{\nstatic int i;\n++i;\nprintf(\u201c%d \u201c,i);\n}\n<\/pre><\/div>\n\n\n<p>If a global variable is static, then its visibility is limited to the same source code.<\/p>\n\n\n\n<p><strong>Q #31) What is the purpose of the Extern Storage Specifier?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> \u201cExtern\u201d specifier is used to resolve the scope of a global symbol.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream &gt;\n using nam espace std;\n main()\n {\nextern int i;\n cout&lt;&lt;i&lt;&lt;endl;\n }\n int i=20;\n<\/pre><\/div>\n\n\n<p>In the above code, \u201ci\u201d can be visible outside the file where it is defined.<\/p>\n\n\n\n<p><strong>Q #32) Explain the Register Storage Specifier.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> \u201cRegister\u201d variables should be used whenever the variable is used. When a variable is declared with a \u201cregister\u201d specifier, the compiler gives a CPU register for its storage to speed up the lookup of the variable.<\/p>\n\n\n\n<p><strong>Q #33) When to use &#8220;const&#8221; reference arguments in a function?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> <strong>Using \u201cconst\u201d reference arguments in a function is beneficial in several ways:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u201cconst\u201d protects from programming errors that could alter data.<\/li>\n\n\n\n<li>As a result of using \u201cconst\u201d, the function can process both const and non-const actual arguments, which is not possible when \u201cconst\u201d is not used.<\/li>\n\n\n\n<li>Using a const reference will allow the function to generate and use a temporary variable appropriately.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Structure &amp; User-Defined Data Types<\/h4>\n\n\n\n<p><strong>Q #34) What is a Class?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Class is a user-defined data type in C++. It can solve a particular kind of problem. After creation, the user is not required to know the details of the working of a class.<\/p>\n\n\n\n<p>In general, a class acts as a blueprint of a project and can include various parameters and functions or actions operating on these parameters. These are called the members of the class.<\/p>\n\n\n\n<p><strong>Q #35) Difference between Class and Structure.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n\n<p><strong>Structure:<\/strong> In the C language, the structure is used to bundle different types of data types together. The variables inside a structure are called the members of the structure. These members are by default public and can be accessed by using the structure name followed by a dot operator and then the member name.<\/p>\n\n\n\n<p><strong>Class:<\/strong> Class is a successor of the Structure. C++ extends the structure definition to include the functions that operate on its members. By default all the members of the class are private.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Object-Oriented Programming With C++<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Classes, Constructors, Destructors<\/h4>\n\n\n\n<p><strong>Q #36) What is Namespace?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Namespace allows us to group a set of global classes, objects, and\/or functions under a specific name.<\/p>\n\n\n\n<p><strong>The general form to use namespaces is:<\/strong><\/p>\n\n\n\n<p><strong>namespace identifier { namespace-body }<\/strong><\/p>\n\n\n\n<p>Where identifier is any valid identifier, and the namespace-body is the set of classes, objects, and functions that are included within the namespace. Namespaces are especially useful in cases where more than one object can have the same name, resulting in name clashes.<\/p>\n\n\n\n<p><strong>Q #37) What is the use of a &#8216;using&#8217; declaration?<\/strong><\/p>\n\n\n\n<p><strong>Answer: <\/strong>Declaration is used to refer to a name from the namespace without the scope resolution operator.<\/p>\n\n\n\n<p><strong> Q #38) What is Name Mangling?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The C++ compiler encodes the parameter types of a function\/method into a unique name. This process is called name mangling. The inverse process is called demangling.<\/p>\n\n\n\n<p><strong>Example: <\/strong><\/p>\n\n\n\n<p><strong>A::b(int, long)<\/strong> const is mangled as <strong>&#8216;b__C3Ail&#8217;<\/strong>.<\/p>\n\n\n\n<p>For a constructor, the method name is left out.<\/p>\n\n\n\n<p>That is <strong>A:: A(int, long)<\/strong> const is mangled as <strong>\u2018C3Ail\u2019.<\/strong><\/p>\n\n\n\n<p><strong>Q #39)&nbsp;What is the difference between an Object and a Class?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Class is a blueprint of a project or problem to be solved and consists of variables and methods. These are called the members of the class. We cannot access methods or variables of the class on its own unless they are declared static.<\/p>\n\n\n\n<p>To access the class members and put them to use, we should create an instance of a class, which is called an Object. The class has an unlimited lifetime, whereas an object has a limited lifespan.<\/p>\n\n\n\n<p><strong>Q #40) What are the various Access Specifiers in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> <strong>C++ supports the following access specifiers:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Public:<\/strong> Data members and functions are accessible outside the class.<\/li>\n\n\n\n<li><strong>Private:<\/strong> Data members and functions are not accessible outside the class. The exception is the usage of a friend class.<\/li>\n\n\n\n<li><strong>Protected:<\/strong> Data members and functions are accessible only to the derived classes.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Describe PRIVATE, PROTECTED, and PUBLIC, along with their differences, and give examples.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nclass A{\n             int x; int y;\n             public int a;\n             protected bool flag;\n             public A() : x(0) , y(0) {} \/\/default (no argument) constructor\n };\n\n main(){\n \nA MyObj;\n \nMyObj.x = 5; \/\/ Compiler will issue a ERROR as x is private\n \nint x = MyObj.x; \/\/ Compiler will issue a compile ERROR MyObj.x is private\n \n MyObj.a = 10; \/\/ no problem; a is public member\n int col = MyObj.a; \/\/ no problem\n \n MyObj.flag = true; \/\/ Compiler will issue a ERROR; protected values are read only\n bool isFlag = MyObj.flag; \/\/ no problem\n<\/pre><\/div>\n\n\n<p><strong> Q #41) What is a Constructor and what is it called? <\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Constructor is a member function of a class having the same name as the class. It is mainly used for initializing the members of the class. By default, constructors are public.<\/p>\n\n\n\n<p><strong>There are two ways in which the constructors are called:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Implicitly:<\/strong> Constructors are implicitly called by the compiler when an object of the class is created. This creates an object on a Stack.<\/li>\n\n\n\n<li><strong>Explicit Calling:<\/strong> When the object of a class is created using new, constructors are called explicitly. This usually creates an object on a Heap.<\/li>\n<\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nclass A{\n int x; int y; \n public A() : x(0) , y(0) {} \/\/default (no argument) constructor\n };\n main()\n {\n                    A Myobj; \/\/ Implicit Constructor call. In order to allocate memory on stack,\n                                    \/\/the default constructor is implicitly called.\n                  A * pPoint = new A(); \/\/ Explicit Constructor call. In order to allocate\n                                                  \/\/memory on HEAP we call the default constructor.\n }\n<\/pre><\/div>\n\n\n<p><strong>Q #42) What is a COPY CONSTRUCTOR, and when is it called?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>A copy constructor is a constructor that accepts an object of the same class as its parameter and copies its data members to the object on the left side of the assignment. It is useful when we need to construct a new object of the same class.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n class A{\n              int x; int y;\n              public int color;\n              public A() : x(0) , y(0) {} \/\/default (no argument) constructor\n              public A( const A&amp; ) ;\n };\n A::A( const A &amp; p )\n {\n               this-&gt;x = p.x;\n               this-&gt;y = p.y;\n               this-&gt;color = p.color;\n }\n main()\n {\n             A Myobj;\n             Myobj.color = 345;\n             A Anotherobj = A( Myobj ); \/\/ now Anotherobj has color = 345\n }\n<\/pre><\/div>\n\n\n<p><strong> Q #43) What is a Default Constructor?<\/strong><\/p>\n\n\n\n<p><strong>Answer: A default<\/strong>&nbsp;constructor is a constructor that either has no arguments or, if there are any, then all of them are default arguments.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nclass B {\n public: B (int m = 0) : n (m) {} int n;\n }; \n int main(int argc, char *argv&#x5B;])\n{\n B b; return 0;\n } \n<\/pre><\/div>\n\n\n<p><strong> Q #44) What is a Conversion Constructor?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> It is a constructor that accepts one argument of a different type. Conversion constructors are mainly used for converting from one type to another.<\/p>\n\n\n\n<p><strong> Q #45) What is an Explicit Constructor?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> A conversion constructor is declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. Its purpose is reserved explicitly for construction.<\/p>\n\n\n\n<p><strong>Q #46) What is the role of the Static keyword for a class member variable?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The static member variable shares a common memory across all the objects created for the respective class. We need not refer to the static member variable using an object. However, it can be accessed using the class name itself.<\/p>\n\n\n\n<p><strong>Q #47) Explain the Static Member Function.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> A static member function can access only the static member variable of the class. Similarly, users can access a static member function using the class name.<\/p>\n\n\n\n<p><strong> Q #48) What&#8217;s the order in which the local objects are destructed?<\/strong><\/p>\n\n\n\n<p><strong>Answer: Consider the following piece of code:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nClass A{\n \u2026.\n };\n int main()\n {\n A a;\n A b;\n ...\n }\n<\/pre><\/div>\n\n\n<p>In the main function, we have two objects created one after the other. They are created in order, first a then b. But when these objects are deleted or if they go out of scope, the destructor for each will be called in the reverse order in which they were constructed.<\/p>\n\n\n\n<p>Hence, the destructor of b will be called first, followed by a. Even if we have an array of objects, they will be destructed in the same way in the reverse order of their creation.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Overloading<\/h4>\n\n\n\n<p><strong>Q #49) Explain Function Overloading and Operator Overloading.<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>C++ supports the OOPs concept of Polymorphism which means \u201cmany forms\u201d.<\/p>\n\n\n\n<p>In C++, we have two types of polymorphism, i.e. Compile-time polymorphism, and Run-time polymorphism. Compile-time polymorphism is achieved by using an Overloading technique. Overloading simply means giving additional meaning to an entity by keeping its base meaning intact.<\/p>\n\n\n\n<p><strong>C++ supports two types of overloading:<\/strong><\/p>\n\n\n\n<p><strong>Function Overloading:<\/strong><\/p>\n\n\n\n<p>Function overloading is a technique that allows the programmer to have more than one function with the same name but a different parameter list. In other words, we overload the function with different arguments, i.e., be it the type of arguments, the number of arguments, or the order of arguments.<\/p>\n\n\n\n<p>Function overloading is never achieved on its return type.<\/p>\n\n\n\n<p><strong>Operator Overloading: <\/strong><\/p>\n\n\n\n<p>This is yet another type of compile-time polymorphism that is supported by C++. In operator overloading, an operator is overloaded, so that it can operate on the user-defined types and operands of the standard data type. But while doing this, the standard definition of that operator is kept intact.<\/p>\n\n\n\n<p><strong>For Example,<\/strong> an Addition operator (+) that operates on numerical data types can be overloaded to operate on two objects just like an object of a complex number class.<\/p>\n\n\n\n<p><strong>Q #50) What is the difference between Method Overloading and Method Overriding in C++?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Method overloading is having functions with the same name but different argument lists. This is a form of compile-time polymorphism.<\/p>\n\n\n\n<p>Method overriding comes into the picture when we rewrite the method that is derived from a base class. Method overriding is used while dealing with run-time polymorphism or virtual functions.<\/p>\n\n\n\n<p><strong> Q #51) What is the difference between a Copy Constructor and an Overloaded<\/strong><strong> Assignment Operator?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>A copy constructor and an overloaded assignment operator serve the same purpose, i.e., assigning the content of one object to another. But still, there is a difference between the two.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n complex c1,c2;\n c1=c2; \/\/this is assignment\n complex c3=c2; \/\/copy constructor \n<\/pre><\/div>\n\n\n<p>In the above example, the second statement c1 = c2 is an overloaded assignment statement.<\/p>\n\n\n\n<p>Here, both c1 and c2 are already existing objects, and the contents of c2 are assigned to the object c1. Hence, for an overloaded assignment statement, both objects need to be created already.<\/p>\n\n\n\n<p>The next statement, complex c3 = c2 is an example of the copy constructor. Here, the contents of c2 are assigned to a new object c3, which means the copy constructor creates a new object whenever it executes.<\/p>\n\n\n\n<p><strong> Q #52)&nbsp;Name the Operators that cannot be Overloaded.<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>sizeof \u2013 sizeof operator<\/li>\n\n\n\n<li>. &#8211; Dot operator<\/li>\n\n\n\n<li>.* &#8211; dereferencing operator<\/li>\n\n\n\n<li>-&gt; &#8211; member dereferencing operator<\/li>\n\n\n\n<li>:: &#8211; scope resolution operator<\/li>\n\n\n\n<li>?: &#8211; conditional operator<\/li>\n<\/ul>\n\n\n\n<p><strong>Q #53) Function can be overloaded based on the parameter, which is a value or a reference. Explain if the statement is true.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> False. Both, Passing by value and Passing by reference look identical to the caller.<\/p>\n\n\n\n<p><strong> Q #54) What are the benefits of Operator Overloading?<\/strong><\/p>\n\n\n\n<p><strong>Answer: <\/strong>By overloading standard operators on a class, we can extend the meaning of these operators, so that they can also operate on other user-defined objects.<\/p>\n\n\n\n<p>Function overloading allows us to reduce the complexity of the code and make it clearer and more readable, as we can have the same function names with different argument lists.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Inheritance<\/h4>\n\n\n\n<p><strong>Q #55) What is Inheritance?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> Inheritance is a process by which we can acquire the characteristics of an existing entity and form a new entity by adding more features to it.<\/p>\n\n\n\n<p>In terms of C++, inheritance is creating a new class by deriving it from an existing class so that this new class has the properties of its parent class and its own.<\/p>\n\n\n\n<p><strong> Q #56) What are the advantages of Inheritance?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Inheritance allows code re-usability, thereby saving time on code development.<\/p>\n\n\n\n<p>By inheriting, we make use of bug-free, high-quality software that reduces future problems.<\/p>\n\n\n\n<p><strong>Q #57) Does C++ support Multilevel and Multiple Inheritance?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> Yes.<\/p>\n\n\n\n<p><strong> Q #58) What are Multiple Inheritances (virtual inheritance)? What are its advantages and disadvantages?<\/strong><\/p>\n\n\n\n<p><strong>Answer: <\/strong>In multiple inheritance, we have more than one base class from which a derived class can inherit. Hence, a derived class takes the features and properties of more than one base class.<\/p>\n\n\n\n<p>For Example, a class driver will have two base classes, namely, an <strong>employee <\/strong>and a person because a driver is an employee as well as a person. This is advantageous because the driver class can inherit the properties of the employee as well as the person class.<\/p>\n\n\n\n<p>But in the case of an employee and a person, the class will have some properties in common. However, an ambiguous situation will arise as the driver class will not know the classes from which the common properties should be inherited. This is the major disadvantage of multiple inheritance.<\/p>\n\n\n\n<p><strong>Q #59) Explain the ISA and HASA class relationships. How would you implement&nbsp;<\/strong><strong>each?<\/strong><\/p>\n\n\n\n<p><strong>Answer:\u00a0<\/strong>\u201cISA\u201d relationship usually exhibits inheritance as it implies that a class \u201cISA\u201d specialized version of another class. For example,\u00a0an employee ISA person. That means an Employee class is inherited from the Person class.<\/p>\n\n\n\n<p>Contrary to \u201cISA\u201d, \u201cHASA\u201d relationship depicts that an entity may have another entity as its member or a class has another object embedded inside it.<\/p>\n\n\n\n<p>So taking the same example of an Employee class, the way in which we associate the Salary class with the employee is not by inheriting it but by including or containing the Salary object inside the Employee class. \u201cHASA\u201d relationship is best exhibited by containment or aggregation.<\/p>\n\n\n\n<p><strong> Q #60) Does a derived class inherit or doesn&#8217;t inherit?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> When a derived class is constructed from a particular base class, it inherits all the features and ordinary members of the base class. But there are some exceptions to this rule. For instance, a derived class does not inherit the base class\u2019s constructors and destructors.<\/p>\n\n\n\n<p>Each class has its constructors and destructors. The derived class also does not inherit the assignment operator of the base class and friends of the class. The reason is that these entities are specific to a particular class and if another class is derived or if it is the friend of that class, then they cannot be passed on to them.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Polymorphism<\/h4>\n\n\n\n<p><strong> Q #61) What is Polymorphism?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The basic idea behind polymorphism is in many forms. In C++, we have two types of Polymorphism:<\/p>\n\n\n\n<p><strong>(i) Compile-time Polymorphism<\/strong><\/p>\n\n\n\n<p>In compile-time polymorphism, we achieve many forms by overloading. Hence, we have an Operator overloading and function overloading. (We have already covered this above)<\/p>\n\n\n\n<p><strong>(ii) Run-time Polymorphism<\/strong><\/p>\n\n\n\n<p>This is the polymorphism for classes and objects. The general idea is that a base class can be inherited by several classes. A base class pointer can point to its child class and a base class array can store different child class objects.<\/p>\n\n\n\n<p>This means, that an object reacts differently to the same function call. This type of polymorphism can use a virtual function mechanism.<\/p>\n\n\n\n<p><strong> Q #62) What are Virtual Functions?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> A virtual function allows the derived classes to replace the implementation provided by the base class.<\/p>\n\n\n\n<p>Whenever we have functions with the same name in the base as well as the derived class, there arises an ambiguity when we try to access the child class object using a base class pointer. As we are using a base class pointer, the function that is called is the base class function with the same name.<\/p>\n\n\n\n<p>To correct this ambiguity, we use the keyword \u201cvirtual\u201d before the function prototype in the base class. In other words, we make this polymorphic function Virtual. By using a Virtual function, we can remove the ambiguity and we can access all the child class functions correctly using a base class pointer.<\/p>\n\n\n\n<p><strong> Q #63) Give an example of Run-time Polymorphism\/Virtual Functions.<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nclass SHAPE{\n                  public virtual Draw() = 0; \/\/abstract class with a pure virtual method\n };\n class CIRCLE: public SHAPE{\n                  public int r;\n                  public Draw() { this-&gt;drawCircle(0,0,r); }\n };\nclass SQUARE: public SHAPE{\n               public int a;\n               public Draw() { this-&gt;drawSquare(0,0,a,a); }\n };\n\n int main()\n {\n                SHAPE shape1*;\n                SHAPE shape2*;\n \n                CIRCLE c1;\n                SQUARE s1;\n \n               shape1 = &amp;c1;\n              shape2 = &amp;s1;\n             cout&lt;&lt;shape1-&gt;Draw(0,0,2);\n             cout&lt;&lt;shape2-&gt;Draw(0,0,10,10);\n }\n<\/pre><\/div>\n\n\n<p>In the above code, the SHAPE class has a pure virtual function and is an abstract class (which cannot be instantiated). Each class is derived from SHAPE, implementing the Draw () function in its own way.<\/p>\n\n\n\n<p>Further, each Draw function is virtual so that when we use a base class (SHAPE) pointer with an object of the derived classes (Circle and SQUARE), then the appropriate Draw functions are called.<\/p>\n\n\n\n<p><strong> Q #64) What do you mean by Pure Virtual Functions?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> A Pure Virtual Member Function is a member function in which the base class forces the derived classes to override. Normally, this member function has no implementation. Pure virtual functions are equated to zero.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nclass Shape { public: virtual void draw() = 0; };\n<\/pre><\/div>\n\n\n<p>A base class that has a pure virtual function as its member can be termed an \u201cAbstract class\u201d. This class cannot be instantiated and it usually acts as a blueprint that has several sub-classes with further implementation.<\/p>\n\n\n\n<p><strong>Q #65) What are Virtual Constructors\/Destructors?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><\/p>\n\n\n\n<p><strong>Virtual Destructors:<\/strong> When we use a base class pointer pointing to a derived class object and use it to destroy it, then instead of calling the derived class destructor, the base class destructor is called.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nClass A{\n              \u2026.\n              ~A();\n};\nClass B:publicA{\n               \u2026\n               ~B();\n};\nB b;\nA a = &b;\ndelete a;\n<\/pre><\/div>\n\n\n<p>As shown in the above example, when we say delete, the destructor is called, but it\u2019s the base class destructor. This gives rise to the ambiguity that all the memory held by b will not be cleared properly.<\/p>\n\n\n\n<p>This problem can be solved by using the \u201cVirtual Destructor\u201d concept.<\/p>\n\n\n\n<p>What we do is, we make the base class constructor \u201cVirtual\u201d so that all the child class destructors also become virtual, and when we delete the object of the base class pointing to the object of the derived class, the appropriate destructor is called, and all the objects are properly deleted.<\/p>\n\n\n\n<p><strong>This is shown as follows:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n Class A{\n               \u2026.\n               virtual ~A();\n };\n Class B:publicA{\n                \u2026\n                ~B();\n };\n B b;\n A a = &b;\n delete a; \n<\/pre><\/div>\n\n\n<p><strong>Virtual constructor<\/strong>: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Friend<\/h4>\n\n\n\n<p><strong> Q #66) What is a friend function?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> The C++ class does not allow its private and protected members to be accessed outside the class. But this rule can be violated by making use of the \u201c<strong>Friend<\/strong>\u201d function.<\/p>\n\n\n\n<p>As the name itself suggests, the friend function is an external function that is a friend of the class. For the friend function to access the private and protected methods of the class, we should have a prototype of the friend function with the keyword \u201cfriend\u201d included inside the class.<\/p>\n\n\n\n<p><strong>Q #67) What is a friend class?<\/strong><\/p>\n\n\n\n<p><strong>Answer:&nbsp;<\/strong>Friend classes are used when we need to override the rule for private and protected access specifiers so that two classes can work closely with each other.<\/p>\n\n\n\n<p>Hence, we can have a friend class to be a friend of another class. This way, friend classes can keep private, inaccessible things the way they are.<\/p>\n\n\n\n<p>When we have a requirement to access the internal implementation of a class (private member) without exposing the details by making them public, we go for friend functions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced C++<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Templates<\/h4>\n\n\n\n<p><strong> Q #68) What is a template?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> Templates allow the creation of functions that are independent of data type (generic) and can take any data type as parameters and return value without having to overload the function with all the possible data types. Templates nearly fulfill the functionality of a macro.<\/p>\n\n\n\n<p><strong>Its prototype is any of the following ones:<\/strong><\/p>\n\n\n\n<p><strong><em> template &lt;class <\/em><\/strong><em>identifier<\/em><strong><em>&gt; <\/em><\/strong><em>function_declaration;<\/em><\/p>\n\n\n\n<p><strong><em> template &lt;typename <\/em><\/strong><em>identifier<\/em><strong><em>&gt; <\/em><\/strong><em>function_declaration;<\/em><\/p>\n\n\n\n<p>The only difference between the two prototypes is the use of the keyword class or typename. Their basic functionality of being generic remains the same.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Exception Handling<\/h4>\n\n\n\n<p><strong>Q #69) What is Exception Handling? Does C++ support Exception Handling? <\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> Yes, C++ supports exception handling.<\/p>\n\n\n\n<p>We cannot ensure that the code will execute normally at all times. There can be certain situations that might force the code written by us to malfunction, even though it\u2019s error-free. This malfunctioning of code is called an <strong>Exception<\/strong>.<\/p>\n\n\n\n<p>When an exception has occurred, the compiler has to throw it so that we know an exception has occurred. When an exception has been thrown, the compiler has to ensure that it is handled properly, so that the program flow continues or terminates properly. This is called the <strong>handling of an exception.<\/strong><\/p>\n\n\n\n<p>Thus in C++, we have three keywords i.e., <strong>try<\/strong>, <strong>throw,<\/strong> and <strong>catch,\u00a0<\/strong>which are in exception handling.<\/p>\n\n\n\n<p><strong>The general syntax for exception block is:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\ntry{\n \u2026. \n # Code that is potentially about to throw exception goes here\n \u2026.\n throw exception;\n }\n catch(exception type) {\n \u2026\n #code to handle exception goes here\n }\n<\/pre><\/div>\n\n\n<p>As shown above, the code that might potentially malfunction is put under the try block. When code malfunctions, an exception is thrown. This exception is then caught under the catch block and is handled i.e. appropriate action is taken.<\/p>\n\n\n\n<p><strong> Q #70) Comment on C++ standard exceptions?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> C++ supports some standard exceptions that can be caught if we put the code inside the try block. These exceptions are a part of the base class \u201c<strong>std:: exception\u201d.<\/strong> This class is defined in the C++ header file <strong>&lt;exception&gt;<\/strong>.<\/p>\n\n\n\n<p><strong>A few Examples of Exceptions supported by this class include:<\/strong><\/p>\n\n\n\n<p><em>bad_alloc \u2013 thrown by \u2018new\u2019<\/em><\/p>\n\n\n\n<p><em> runtime_error \u2013 thrown for runtime errors<\/em><\/p>\n\n\n\n<p><em> bad_typeid \u2013 thrown by type id<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Introduction to Standard Template Library<\/h4>\n\n\n\n<p><strong>Q #71) What is a Standard Template Library (STL)? What are the various types of STL Containers?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong> A Standard Template Library (STL) is a library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. We have various types of STL containers depending on how they store the elements.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Queue, and <\/strong>Stack \u2013 These are the same as traditional queues and stacks and are called adaptive containers.<\/li>\n\n\n\n<li><strong>Set, Map<\/strong> \u2013 These are containers that have key\/value pairs and are associative.<\/li>\n\n\n\n<li><strong>Vector, deque<\/strong> \u2013 These are sequential and have similarities to arrays.<\/li>\n<\/ol>\n\n\n\n<p><strong>Q #72) What is an Iterator class?<\/strong><\/p>\n\n\n\n<p><strong class=\"\">Answer:&nbsp;<\/strong>In C++ a container class is a collection of different objects.<\/p>\n\n\n\n<p>If we need to traverse through this collection of objects, we cannot do it using simple index variables. Hence, we have a special class in STL called an <strong>Iterator<\/strong> class, which can step through the contents of the container class.<\/p>\n\n\n\n<p><strong>The various categories of iterators include<\/strong> input iterators, output iterators, forward iterators, bidirectional iterators, random access, etc.<\/p>\n\n\n\n<p><strong>Q #73) What is the difference between an External Iterator and an Internal Iterator? <\/strong><strong>Describe an advantage of the External Iterator.<\/strong><\/p>\n\n\n\n<p><strong>Answer: <\/strong>An internal iterator is implemented with member functions of the class that have items to step through.<\/p>\n\n\n\n<p>An external iterator is implemented as a separate class that can be bound to the object that has items to step through. The basic advantage of an External iterator is that it\u2019s easy to implement as it is implemented as a separate class.<\/p>\n\n\n\n<p>Secondly, as it\u2019s a different class, many iterator objects can be active simultaneously.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts on C++ Developer Interview Questions<\/h2>\n\n\n\n<p>Almost all the major coding and programming topics of C++ interviews are covered in this article.<\/p>\n\n\n\n<p>We hope that any candidate will feel relaxed after preparing for an interview using this series of interview questions.<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.softwaretestinghelp.com\/c-programming-interview-questions\/\" target=\"_blank\" rel=\"noopener\">Top C Programming Interview Questions<\/a><\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.softwaretestinghelp.com\/c-sharp-interview-questions\/\" target=\"_blank\" rel=\"noopener\">C# Interview Questions<\/a><\/strong><\/p>\n\n\n\n<p><em><strong>All the best for your Interview!!<\/strong><\/em><\/p>\n\n\n\n<p><\/p>\n\r\n\t\t\t<div id=\"daexthefup-container\"\r\n\t\t\t\tclass=\"daexthefup-container daexthefup-layout-stacked daexthefup-alignment-center\"\r\n\t\t\t\tdata-post-id=\"46473\">\r\n\r\n\t\t\t\t<div class=\"daexthefup-feedback\">\r\n\t\t\t\t\t<div class=\"daexthefup-text\">\r\n\t\t\t\t\t\t<h3 class=\"daexthefup-title\">Was this helpful?<\/h3>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<div class=\"daexthefup-buttons-container\">\r\n\t\t\t\t\t\t<div class=\"daexthefup-buttons\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-yes daexthefup-button daexthefup-button-type-icon\" data-value=\"1\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-up-cls-1{fill:#c9c9c9;}.thumb-up-cls-2{fill:#e1e1e1;}.thumb-up-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_up\">\r\n                        <path class=\"thumb-up-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-up-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"20\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,9.06l-.49-.1c-.81-.17-1.61.35-1.78,1.16l-5.3,11.74c-.17.81,3.16,1.61,3.97,1.78l1.96.41c.81.17,1.61-.35,1.78-1.16l2.18-10.27c.34-1.61-.7-3.21-2.31-3.56Z\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,20h-18.67c-.83,0-1.5.67-1.5,1.5v12c0,.83.67,1.5,1.5,1.5h16.27c.71,0,1.33-.5,1.47-1.21l2.4-12c.19-.93-.53-1.8-1.47-1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-no daexthefup-button daexthefup-button-type-icon\" data-value=\"0\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-down-cls-1{fill:#c9c9c9;}.thumb-down-cls-2{fill:#e1e1e1;}.thumb-down-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_down\">\r\n                        <path class=\"thumb-down-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-down-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"13\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,38.94l-.49.1c-.81.17-1.61-.35-1.78-1.16l-5.3-11.74c-.17-.81,3.16-1.61,3.97-1.78l1.96-.41c.81-.17,1.61.35,1.78,1.16l2.18,10.27c.34,1.61-.7,3.21-2.31,3.56Z\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,28h-18.67c-.83,0-1.5-.67-1.5-1.5v-12c0-.83.67-1.5,1.5-1.5h16.27c.71,0,1.33.5,1.47,1.21l2.4,12c.19.93-.53,1.8-1.47,1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-comment\">\r\n\t\t\t\t\t<div class=\"daexthefup-comment-top-container\">\r\n\t\t\t\t\t\t<label id=\"daexthefup-comment-label\" class=\"daexthefup-comment-label\"><\/label>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-container\">\r\n\t\t\t\t\t\t\t\t<div id=\"daexthefup-comment-character-counter-number\"\r\n\t\t\t\t\t\t\t\t\tclass=\"daexthefup-comment-character-counter-number\"><\/div>\r\n\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-text\"><\/div>\r\n\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<textarea id=\"daexthefup-comment-textarea\" class=\"daexthefup-comment-textarea\"\r\n\t\t\t\t\t\t\t\tplaceholder=\"Type your message\"\r\n\t\t\t\t\t\t\t\tmaxlength=\"\r\n\t\t\t\t\t\t\t\t400\t\t\t\t\t\t\t\t\t\"><\/textarea>\r\n\t\t\t\t\t<div class=\"daexthefup-comment-buttons-container\">\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-submit daexthefup-button\">Submit<\/button>\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-cancel daexthefup-button\">Cancel<\/button>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-successful-submission-text\">Thanks for your feedback!<\/div>\r\n\r\n\t\t\t<\/div>\r\n\r\n\t\t\t","protected":false},"excerpt":{"rendered":"<p>Most frequently asked basic and advanced C++ interview questions with code examples for entry-level candidates and experienced professionals: This detailed article will undoubtedly be a valuable resource for those preparing for a C++ interview. Almost all major topics in C++ are covered here, along with some basic questions on advanced &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"TOP 70 C++ Interview Questions and Answers [Includes Advanced]\" class=\"read-more button\" href=\"https:\/\/www.softwaretestinghelp.com\/cpp-interview-questions\/#more-46473\" aria-label=\"Read more about TOP 70 C++ Interview Questions and Answers [Includes Advanced]\">Read more<\/a><\/p>\n","protected":false},"author":9,"featured_media":229417,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_helpful_pro_status":1,"footnotes":""},"categories":[368],"tags":[],"class_list":{"0":"post-46473","1":"page","2":"type-page","3":"status-publish","4":"has-post-thumbnail","6":"category-interview-preparation"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/46473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/comments?post=46473"}],"version-history":[{"count":24,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/46473\/revisions"}],"predecessor-version":[{"id":412433,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/46473\/revisions\/412433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media\/229417"}],"wp:attachment":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media?parent=46473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/categories?post=46473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/tags?post=46473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}