My Report

C++ Programming Mock Test 2


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

Question 1 of 10

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

    #include <iostream>
    using namespace std;
    int main()
    {
        int i;
        for (i = 0; i < 10; i++);
        {
            cout << i;
        }
        return 0;
    } 

Question 1 of 10

Question 2 of 10

2. When we define the default values for a function?

Question 2 of 10

Question 3 of 10

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

    #include <iostream>
    using namespace std;
    int main()
    {
        int a = 5, b = 10, c = 15;
        int *arr[ ] = {&a, &b, &c};
        cout << arr[1];
        return 0;
    } 

Question 3 of 10

Question 4 of 10

4. Which of the following correctly declares an array?

Question 4 of 10

Question 5 of 10

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

    #include <iostream>
    using namespace std;
    int main()
    {
        int a;
        a = 5 + 3 * 5;
        cout << a;
        return 0;
    } 

Question 5 of 10

Question 6 of 10

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

    #include <iostream>
    using namespace std;
    int main()
    {
        struct ShoeType 
        {
           string style;
           double price;
        };
         ShoeType shoe1, shoe2;
         shoe1.style = "Adidas";
         shoe1.price = 9.99;
         cout << shoe1.style << " $ "<< shoe1.price;
         shoe2 = shoe1;
         shoe2.price = shoe2.price / 9;
         cout << shoe2.style << " $ "<< shoe2.price;
         return 0;
    } 

Question 6 of 10

Question 7 of 10

7. Which function is used to check whether a character is hexadecimal?

Question 7 of 10

Question 8 of 10

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

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(int argc, char const *argv[])
{
	int &p;
	int a = 5;
	&p = a;
	cout<<p;
	return 0;
}

Question 8 of 10

Question 9 of 10

9. What will happen when defining the enumerated type?

Question 9 of 10

Question 10 of 10

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

    #include <iostream>
    using namespace std;
    void swap(int &a, int &b);
    int main()
    {
        int a = 5, b = 10;
        swap(a, b);
        cout << "In main " << a << b;
        return 0;
    }
    void swap(int &a, int &b)
    {
        int temp;
        temp = a;
        a = b;
        b = temp;
        cout << "In swap " << a << b;
    } 

Question 10 of 10


 

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.