C++ Programming Quiz


Play this c++ quiz that will help you to excel in C++ certification exams, placements etc. This C++ programming quiz consist of 10 questions that you need to solve in 10 minutes. We’ve specially designed this quiz so that you can quickly acquaint to the pattern of questions you can be asked in placement drives, certification exams etc. This C++ programming test enables you to assess your knowledge of C++ programming.

Take the Free Practice Test



C++ MCQs

Practice C++ MCQ Questions, which will help you to understand C++ programming related concepts and also helps you to prepare for placements, technical rounds, interviews, competitive exams etc.

C++ Quiz

Try Free C++ Quiz, to start a quiz you need to login first, after login you will get start quiz button and then by clicking on that you can start quiz. You will get 10 Minutes to answer all questions.

C++ Quiz

1. Assume that an integer and a pointer each takes 4 bytes. Also, assume that there is no alignment in objects. Predict the output following program.

         
Note:Includes all required header files
using namespace std;
 
class Test
{
    static int x;
    int *ptr;
    int y;
};
 
int main()
{
    Test t;
    cout << sizeof(t) << " ";
    cout << sizeof(Test *);
}

12 12
12 4
8 4
8 8

2. What is the size of empty class?

0
2
4
1

3. Pick out the correct statement about string template?

It is used to replace a string.
It is used to replace a string with another string at runtime.
It is used to delete a string.
None of the above

4. What will be the output of this program?

Note:Includes all required header files
 using namespace std;
     int max(int p, int q )
    {
        return ( p > q ? p : q );
    }
    int main()
    {
        int x = 25;
        int y = 50;
        cout << max(x, y );
        return 0;
    }  

25
50
either 25 or 50
none of the mentioned

5. Which of the following is correct option?

    #include<iostream>
    using namespace std;
    namespace lfc1
    {
        double var =30.1234;
    }
    namespace lfc2
    {
        double var = 13.5478;
    }
    int main ()
    {
        double a;
        a = lfc1::var - lfc2::var;
        cout << a;
        return 0;
   }

16.5756
17
15
16.57

6. Which is the correct statement anout operator overloading in C++?.

Only arithmetic operators can be overloaded
Associativity and precedence of operators does not change
Precedence of operators are changed after overlaoding
Only non-arithmetic operators can be overloaded

7. What will be output for the followiing code?

#include <iostream>
class A { 
private: 
    int a; 
  
public: 
    A() { a = 0; } 
    friend class B; // Friend Class 
}; 
  
class B { 
private: 
    int b; 
  
public: 
    void showA(A& x) 
    { 
         
        std::cout << ""A::a="" << x.a; 
    } 
}; 
  
int main() 
{ 
    A a; 
    B b; 
    b.showA(a); 
  
 }

A::a=0
A
a=0
A::0

8. What will be the output of this program?

        
Note:Includes all required header files
using namespace std;
//Empty class
class test
{
};
 
int main()
{
   test testObj;
   cout<<"size ="<< sizeof(testObj);
   return 0;
}

Error
size =Garbage
size =1
Compile but no output

9. Pick the correct statement.

Friend functions are in the scope of a class
Friend functions can be called using class objects
Friend functions can be invoked as a normal function
Friend functions can access only protected members not the private members

10. How to access the object in the class?

Ternary operator
Scope resolution operator
Direct member access operator
None of the above

Results