My Report (&Account)

C++ Online Test


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)

Here is the complete list of test quizzes on C++.

1. By default, all the files in C++ are opened in _________ mode.

Question 1 of 50 (sanfoundry.com)

2. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    class BaseClass 
    {
        protected:
        int i;
        public:
        BaseClass(int x) 
        {
            i = x;
        }
        ~BaseClass() 
        {
        }
    };
    class DerivedClass: public BaseClass 
    {
        int j;
        public:
        DerivedClass(int x, int y): BaseClass(y)
        {
            j = x;
        }
        ~DerivedClass() 
        {
        }
        void show() 
        {
            cout << i << " " << j << endl;
        }
    };
    int main()
    {
        DerivedClass ob(3, 4);
        ob.show();
        return 0;
    }

Question 2 of 50 (sanfoundry.com)

3. Why do we need to handle exceptions?

Question 3 of 50 (sanfoundry.com)

4. What will be the output of the following C++ code in a 32-bit machine?

    #include <iostream>
    using namespace std;
    int main()
    {
        int num = 0x20 + 020 + 20;
        cout << sizeof(num)<<'\n';
        return 0;
    } 

Question 4 of 50 (sanfoundry.com)

5. What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
    int main() 
    {
        string s = "spaces in text";
        s.erase(remove(s.begin(), s.end(), ' ' ), s.end() ) ;
        cout << s << endl;
    }

Question 5 of 50 (sanfoundry.com)

6. Which of the following is correct about none() function in bitset?

Question 6 of 50 (sanfoundry.com)

7. What happens if the following C++ program is compiled?

#include <iostream>
#include <string>
using namespace std;
class A
{
	int a;
   public: 
	A(){
		a = 0;
	}
	void show(){
		a++;
		cout<<"a: "<<a<<endl;
	}
};

class B: private A
{
   public:
	void show(){
		show();
	}
};

int main(int argc, char const *argv[])
{
	B b;
	b.show();
	return 0;
}

Question 7 of 50 (sanfoundry.com)

8. What will be the output of the following C++ code?

  
    #include <iostream>
    using namespace std;
    int main ()
    {
        int n;
        n = -77;
        cout.width(4); 
        cout << internal << n << endl;
        return 0;
    }

Question 8 of 50 (sanfoundry.com)

9. Which of the following is the default return value of functions in C++?

Question 9 of 50 (sanfoundry.com)

10. Which keyword is used to declare the min and max functions?

Question 10 of 50 (sanfoundry.com)

11. What are the essential operators in c++?

Question 11 of 50 (sanfoundry.com)

12. Is the size of character literals different in C and C++?

Question 12 of 50 (sanfoundry.com)

13. What will be the output of the following C++ code?

  
    #include <iostream>
    #include <exception>
    using namespace std;
    void myunexpected ()
    {
        cout << "unexpected called\n";
        throw 0;
    }
    void myfunction () throw (int) 
    {
        throw 'x';
    }
    int main () 
    {
        set_unexpected (myunexpected);
        try 
        {
            myfunction();
        }
        catch (int) 
        {
            cout << "caught int\n";
        }
        catch (...)  
        { 
            cout << "caught other exception\n"; 
        }
        return 0;
    }

Question 13 of 50 (sanfoundry.com)

14. Which of the following is correct?

Question 14 of 50 (sanfoundry.com)

15. Which value is pointed out first in heap?

Question 15 of 50 (sanfoundry.com)

16. What will be the output of the following C++ code?

    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
        vector<bool> mask;
        mask.push_back(true);
        mask.flip();
        cout << boolalpha;
        for (unsigned i = 0; i < mask.size(); i++)
        cout << mask.at(i);
        return 0;
    }

Question 16 of 50 (sanfoundry.com)

17. Which operators are used in the free store?

Question 17 of 50 (sanfoundry.com)

18. What is the order of Destructors call when the object of derived class B is declared, provided class B is derived from class A?

Question 18 of 50 (sanfoundry.com)

19. Which word is used to stop the unpacking of a value in a tuple?

Question 19 of 50 (sanfoundry.com)

20. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    int main()
    {
        char *ptr;
        char Str[] = "abcdefg";
        ptr = Str;
        ptr += 5;
        cout << ptr;
        return 0;
    } 

Question 20 of 50 (sanfoundry.com)

21. What will be the output of the following C++ code?

 
    #include <iostream>
    using namespace std;
    class class0 
    {
        public:
        virtual ~class0(){}
        protected:
        char p;
        public:
        char getChar();
    };
    class class1 : public class0 
    {
        public:
        void printChar();
    };
    void class1::printChar()
    {
        cout  << "True" << endl;
    }
    int main() 
    {
        class1 c;
        c.printChar();
        return 1;
    } 

Question 21 of 50 (sanfoundry.com)

22. In which type of semantics does c++ implements iterator?

Question 22 of 50 (sanfoundry.com)

23. Pick the correct statement.

Question 23 of 50 (sanfoundry.com)

24. Which is present in the basic interface of the allocator interface?

Question 24 of 50 (sanfoundry.com)

25. What type of access does deque and vector provide?

Question 25 of 50 (sanfoundry.com)

26. What will be the output of the following C++ code?

#include <iostream>
#include <valarray>
using namespace std;
int main()
{
    valarray<int> varr = { 10, 2, 20, 1, 30 };
    for (int &x: varr) cout << x << " ";
    cout<<endl;
    varr = varr.apply([](int x){return x+=5;});
    for (int &x: varr) cout << x << " ";
    return 0;
}

Question 26 of 50 (sanfoundry.com)

27. What will be the output of the following C++ code?

  
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("Steve jobs");
        cout << str.capacity() << "\n";
        return 0;
    }

Question 27 of 50 (sanfoundry.com)

28. Pick out the correct statement about multiple inheritances.

Question 28 of 50 (sanfoundry.com)

29. Pick the incorrect statement about inline functions in C++?

Question 29 of 50 (sanfoundry.com)

30. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    int main()
    {
        int num1 = 10;
        float num2 = 20;
        cout << sizeof(num1 + num2);
        return 0;
    } 

Question 30 of 50 (sanfoundry.com)

31. What are the advantages of passing arguments by reference?

Question 31 of 50 (sanfoundry.com)

32. Pick out the correct statement.

Question 32 of 50 (sanfoundry.com)

33. In which part of the for loop termination condition is checked?
for(I;II;III)
{IV}

Question 33 of 50 (sanfoundry.com)

34. How many ways of passing a parameter are there in c++?

Question 34 of 50 (sanfoundry.com)

35. What will be the output of the following C++ code?

#include <stdio.h>
int main()
{
   const int x;
   x = 10;
   printf("%d", x);
   return 0;
}

Question 35 of 50 (sanfoundry.com)

36. In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?

Question 36 of 50 (sanfoundry.com)

37. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?

Question 37 of 50 (sanfoundry.com)

38. Which container is used to store elements as key-value pair?

Question 38 of 50 (sanfoundry.com)

39. What is a copy constructor?

Question 39 of 50 (sanfoundry.com)

40. What will be the output of the following C++ code?

  
    #include <iostream>
    #include <set>
    using namespace std;
    int main()
    {
        set<int> tst;
        tst.insert(12);
        tst.insert(21);
        tst.insert(32);
        tst.insert(31);
        set<int> :: const_iterator pos;
        for(pos = tst.begin(); pos != tst.end(); ++pos)
        cout << *pos << ' ';
        return 0;
    }

Question 40 of 50 (sanfoundry.com)

41. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
template <class T>
class Test
{
  private:
    T val;
  public:
    static int count;
    Test()  {   
    	count++;   
    }
};
template<class T>
int Test<T>::count = 0;
int main()
{
    Test<int> a;
    Test<int> b;
    Test<double> c;
    cout << Test<int>::count << endl;
    cout << Test<double>::count << endl;
    return 0;
}

Question 41 of 50 (sanfoundry.com)

42. What is the use of no linkage?

Question 42 of 50 (sanfoundry.com)

43. Which of the following statements is NOT valid about operator overloading?

Question 43 of 50 (sanfoundry.com)

44. Which constructor will initialize the base class data member?

Question 44 of 50 (sanfoundry.com)

45. Identify the incorrect option.

Question 45 of 50 (sanfoundry.com)

46. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    class base
    {
        int val1, val2;
        public:
        int get()
	{
            val1 = 100;
            val2 = 300;
	}
        friend float mean(base ob);
    };
    float mean(base ob)
    {
        return float(ob.val1 + ob.val2) / 2;
    }
    int main()
    {
        base obj;
        obj.get();
        cout << mean(obj);
        return 0;
    }

Question 46 of 50 (sanfoundry.com)

47. Which of the following is correct about bitset and vector of bools?

Question 47 of 50 (sanfoundry.com)

48. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    void PrintSequence(int StopNum)
    {
        int Num;
        Num = 1;
        while (true)
        {
            if (Num >= StopNum)
                throw Num;
            cout << Num << endl;
            Num++;
        }
    }
    int main(void)
    {
        try
        {
            PrintSequence(2);
        }
        catch(int ExNum)
        {
            cout << "exception: " << ExNum << endl;
        }
        return 0;
    }

Question 48 of 50 (sanfoundry.com)

49. What will the monetary facet will do?

Question 49 of 50 (sanfoundry.com)

50. Which of the following function is used to initialize a tuple?

Question 50 of 50 (sanfoundry.com)


 

Topic wise Test Quizzes on C++

C++ tests, quizzes, and exams are great ways to learn and test your C++ programming skills. Whether you’re a beginner or experienced, challenge and boost your confidence with our engaging online quizzes on C++ Basics, OOPs, Array, Pointers, Function, Classes, Exceptions, Namespace, STL and Advanced C++. Start the C++ online test now!



C++ Programming Certification Test

C++ Programming Certification Test is a free certification exam. However, you need to score an A grade in each of the "Certification Level Tests 1 to 10" to be eligible to take part in this certification test. So, take all the "10 Tests" starting from Certification Level 1 upto Level 10, before taking the final Certification test.


Level 1 to 10 Tests:
Total Questions: 25, Total Time: 30 min, Correct Answer: 2 points, Wrong Answer: -1 point

Certification Test:
Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

C++ Programming Internship Test

If you scored either Grade A* or Grade A in our C++ Programming Internship Test, then you can apply for Internship at Sanfoundry in C++ Programming.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

C++ Programming Job Test

It is designed to test and improve your skills for a successful career, as well as to apply for jobs.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Note: Before you get started on these series of online tests, you should practice our collection of 1000 MCQs on C++ Programming .

Sanfoundry Scoring & Grading System

Sanfoundry tests and quizzes are designed to provide a real-time online exam experience. Here is what you need to know about them.

  • Scoring System: You get 2 points for each correct answer but lose 1 point for every wrong answer.
  • Grading System: Your grade depends on your final score and can be one of the following:

    • Grade A* - Genius (100%)
    • Grade A - Excellent (80% to 99%)
    • Grade B - Good (60% to 80%)
    • Grade C - Average (40% to 60%)
    • Grade D - Poor (0% to 40%)
advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 20s–40s and exploring new directions in your career, I also offer mentoring. Learn more here.