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. Which of the following operator is used to capture all the external variable by reference?

Question 1 of 50

2. Identify the type of variables.

    typedef char* CHAR;
    CHAR p,q;

Question 2 of 50

3. What is dynamic binding?

Question 3 of 50

4. Which header file is used with input and output operations of C in C++?

Question 4 of 50

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

  
    #include <iostream>
    #include <memory>
    #include <string>
    using namespace std;
    int main ()
    {
        string numbers[] = {"steve", "jobs"};
        pair <string*, ptrdiff_t> result = get_temporary_buffer<string>(2);
        if (result.second>0) 
        {
            uninitialized_copy ( numbers, numbers + result.second, result.first );
            for (int i = 0; i < result.second; i++)
                cout << result.first[i] << " ";
            return_temporary_buffer(result.first);
        }
        return 0;
    }

Question 5 of 50

6. Which specifier makes all the data members and functions of base class inaccessible by the derived class?

Question 6 of 50

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

    #include <iostream>
    using namespace std;
    class Base
    {
        public:
        virtual void print() const = 0;
    };
    class DerivedOne : virtual public Base
    {
        public:
        void print() const
        {
            cout << "1";
        }
    };
    class DerivedTwo : virtual public Base
    {
        public:
        void print() const
        {
            cout << "2";
        }
    };
    class Multiple : public DerivedOne, DerivedTwo
    {
        public:
        void print() const
        {
            DerivedTwo::print();
        }
    };
    int main()
    {
        Multiple both;
        DerivedOne one;
        DerivedTwo two;
        Base *array[ 3 ];
        array[ 0 ] = &both;
        array[ 1 ] = &one;
        array[ 2 ] = &two;
        for ( int i = 0; i < 3; i++ )
        array[ i ] -> print();
        return 0;
    } 

Question 7 of 50

8. What are the Associative Containers?

Question 8 of 50

9. Which of the following operations can be performed on a pair?

Question 9 of 50

10. Pick out the correct syntax of the header file that can be used with C++.

Question 10 of 50

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

#include<iostream>
#include <string>
using namespace std;
template <class T>
class Print
{
   public:
	int operator()(T a){
		cout<<a<<endl;
	}
};
int main()
{
	Print<string> str;
	Print<int> integer;
	int a = 100;
	string s = "Hello Sanfoundry";
	str(s);
	integer(a);
	return 0;
}

Question 11 of 50

12. In how many ways we can handle errors in any class?

Question 12 of 50

13. Which of the following is correct about dynamic polymorphism?

Question 13 of 50

14. What is used to write multi line comment in c++?

Question 14 of 50

15. What do container adapter provide to interface?

Question 15 of 50

16. In which type do the enumerators are stored by the compiler?

Question 16 of 50

17. Which type of relationship is modelled by Association?

Question 17 of 50

18. In nested try-catch block, if the inner catch block gets executed, then______________

Question 18 of 50

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

#include <iostream>

int main(int argc, char const *argv[])
{
	cout<<"Hello World";
	return 0;
}

Question 19 of 50

20. What will be the output of the following C++ code if the string entered by the user is "Hello World"?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	string str;
	cin>>str;
	cout<<str;
	return 0;
}

Question 20 of 50

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

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char str[10];
	cin>>str;
	cout<<str;
	return 0;
}

Question 21 of 50

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

    #include <iostream>
    using namespace std;
    int add(int a, int b);
    int main()
    {
        int i = 5, j = 6;
        cout << add(i, j) << endl;
        return 0;
    }
    int add(int a, int b )
    {
        int sum = a + b;
        a = 7;
        return a + b;
    }

Question 22 of 50

23. Which keyword is used to define the user defined data types?

Question 23 of 50

24. Which function is used to check whether a character is punctuation mark?

Question 24 of 50

25. Pick out the correct syntax of operator conversion.

Question 25 of 50

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

#include <iostream>
#include <string>
using namespace std;
class Mammal
{
   public:
	virtual void Define(){
		cout<<"I'm a Mammal\n";
	}
};

class Human: public Mammal
{
   public:
	void Define(){
		cout<<"I'm a Human\n";
	}
};

class Male: public Human
{
   public:
	void Define(){
		cout<<"I'm a Male\n";
	}
};

class Female: public Human
{
   public:
	void Define(){
		cout<<"I'm a Female\n";
	}
};

int main(int argc, char const *argv[])
{
	Mammal *M;
	Male m;
	Female f;
	*M = m;
	M->Define();
	return 0;
}

Question 26 of 50

27. How compile-time polymorphisms are implemented in C++?

Question 27 of 50

28. Pick the correct statement.

Question 28 of 50

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

  
    #include <iostream>
    #include <iterator>
    #include <vector>
    using namespace std;
    int main () 
    {
        vector<int> myvector;
        for (int i = 0; i < 10; i++) 
            myvector.push_back(i);
        typedef vector<int> :: iterator iter_int;
        reverse_iterator<iter_int> rev_iterator;
        rev_iterator = myvector.rend() - 4;
        cout << *rev_iterator << endl;
        return 0;
    }

Question 29 of 50

30. Identify the incorrect statement.

Question 30 of 50

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

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {1,5,23,90,15,35};
	cout<<is_heap(v.begin(), v.end());
	make_heap(v.begin(), v.end());
	cout<<is_heap(v.begin(), v.end());
}

Question 31 of 50

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

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
    public:
	A(){}
};
class B: public A
{
	int b;
    public:
	B(){}
};

void func()
{
	B b;
	throw b;
}
int main()
{
	try{
		func();
	}
	catch(B *b){
		cout<<"Caught B Class\n";
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
}

Question 32 of 50

33. Which of the following is used for generic programming?

Question 33 of 50

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

  
    #include <iostream>
    using namespace std;
    class three_d 
    {
        int x, y, z;
        public:
        three_d() { x = y = z = 0; }
        three_d(int i, int j, int k) { x = i; y = j; z = k; }
        three_d operator()(three_d obj);
        three_d operator()(int a, int b, int c);
        friend ostream &operator<<(ostream &strm, three_d op);
    };
    three_d three_d::operator()(three_d obj)
    {
        three_d temp;
        temp.x = (x + obj.x) / 2;
        temp.y = (y + obj.y) / 2;
        temp.z = (z + obj.z) / 2;
        return temp;
    }
    three_d three_d::operator()(int a, int b, int c)
    {
        three_d temp;
        temp.x = x + a;
        temp.y = y + b;
        temp.z = z + c;
        return temp;
    }
        ostream &operator<<(ostream &strm, three_d op) {
        strm << op.x << ", " << op.y << ", " << op.z << endl;
        return strm;
    }
    int main()
    {
        three_d objA(1, 2, 3), objB(10, 10, 10), objC;
        objC = objA(objB(100, 200, 300));
        cout << objC;
        return 0;
    }

Question 34 of 50

35. Which of the following function is used to get the actual number of elements stored in vector?

Question 35 of 50

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

    #include <iostream>
    #include <stdarg.h>
    using namespace std;
    int flue(char c,...);
    int main()
    {
        int x, y;
        x = flue('A', 1, 2, 3);
        y = flue('1', 1.0,1, '1', 1.0f, 1l);
        cout << x << y;
        return 0;
    }
    int flue(char c,...)
    {
        return c;
    } 

Question 36 of 50

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

#include <iostream>  
#include <utility>
#include <string>

using namespace std;

int main () 
{
  pair <int,int> p1(1,2);
  pair <int,int> p2(3,4);
  cout<<"Pair(first,second) = ("<<p1.first<<","<<p1.second<<")\n";
  p1.swap(p2);
  cout<<"Pair(first,second) = ("<<p1.first<<","<<p1.second<<")\n";
  return 0;
}

Question 37 of 50

38. Pick the correct statement about references in C++.

Question 38 of 50

39. Function overloading is also similar to which of the following?

Question 39 of 50

40. What happens if the following program is compiled in both C and C++?

#include<stdio.h>
struct STRUCT
{
  int static a;
};
int main()
{
  struct STRUCT s;
  return 0;
}

Question 40 of 50

41. What is mandatory for designing a new container?

Question 41 of 50

42. Which of the following(s) is/are the correct way of assigning values to a forward_list f?

Question 42 of 50

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

    #include <iostream>
    #include <list>
    using namespace std;
    int main ()
    {
        list<int> mylist;
        list<int> :: iterator it1, it2;
        for (int i = 1; i < 10; ++i) mylist.push_back(i * 1);
            it1 = it2 = mylist.begin();
        advance (it2, 6);
        ++it1;
        it1 = mylist.erase (it1);
        it2 = mylist.erase (it2);
        ++it1;
        --it2;
        mylist.erase (it1, it2);
        for (it1 = mylist.begin(); it1 != mylist.end(); ++it1)
            cout << ' ' << *it1;
        return 0;
    }

Question 43 of 50

44. Where does a cin stops it extraction of data?

Question 44 of 50

45. What is another name of full specialization?

Question 45 of 50

46. What is the associativity of add(+);?

Question 46 of 50

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

#include <iostream>
#include <Valarray>
using namespace std;
int main()
{
	Valarray<int> varr = { 1, 2, 3, 4, 5 };
	for (int &x: varr) cout << x << " ";
	cout<<endl;
	varr = varr.shift(-3);
	for (int &x: varr) cout << x << " ";
	return 0;
}

Question 47 of 50

48. What operation can be performed by destructor?

Question 48 of 50

49. In which of the following relationship objects of related classes can occur independently?

Question 49 of 50

50. Which of the following is used to create an output stream?

Question 50 of 50


 

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
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.