My Report

C++ Programming Practice Test 3


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

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

    #include <iostream>
    using namespace std;
    #define PR(id) cout << "The value of " #id " is "<<id
    int main()
    {
        int i = 10;
        PR(i);
        return 0;
    }

2. To use external linkage we have to use which keyword?

3. which of the following can be passed in function pointers?

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

    #include <iostream>
    using namespace std;
    void func(int a, bool flag = true)
    {
        if (flag == true ) 
        {
            cout << "Flag is true. a = " << a;
        }
        else 
        {
            cout << "Flag is false. a = " << a;
        }
    }
    int main()
    {
        func(200, false);
        return 0;
    } 

5. What is the mandatory preprocessor directive for c++?

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

#include <iostream>
#include <string>
using namespace std;
class A
{
	int a = 5;
    public:
	void change(int i){
		a = i;
	}
	static void value_of_a(){
		cout<<a;
	}
};

int main(int argc, char const *argv[])
{
	A a1 = A();
	a1.change(10);
	a1.value_of_a();
	return 0;
}

7. Pick the correct statement.

8. Which category of data type a class belongs to?

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

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

    #include <iostream>
    using namespace std;
    int main()
    {
        int age = 0;
        try 
        {
            if (age < 0) 
            {
                throw "Positive Number Required";
            }
            cout << age;
        }
        catch(const char *Message)
        {
            cout << "Error: " << Message;
        }
        return 0;
    } 

 

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.