adplus-dvertising

Welcome to the Classes and Operator Overloading in C++ MCQs Page

Dive deep into the fascinating world of Classes and Operator Overloading in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Operator Overloading in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Operator Overloading in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Classes and Operator Overloading in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Operator Overloading in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Classes and Operator Overloading in C++ MCQs | Page 8 of 39

Explore more Topics under Object Oriented Programming Using C++

Q71.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample1 
    {
        float i, j;
    };
    class sample2 
    {
        int x, y;
        public:
        sample2 (int a, int b) 
        {
             x = a; 
             y = b;
        }
        int result() 
        { 
             return x + y;
         }
    };
    int main () 
    {
        sample1 d;
        sample2 * padd;
        padd = (sample2*) &d;
        cout < result();
        return 0;
    }
Discuss
Answer: (d).runtime error or random number
Q72.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample
    {
        public:
        sample(int i) : m_i(i) { }
        public:
        int operator()(int i = 0) const 
        { 
            return m_i + i; 
        }
        operator int () const   
        { 
            return m_i; 
        }
        private:
        int m_i;
        friend int g(const sample&);
    };
    int f(char c)
    {
        return c;
    }
    int main()
    {
        sample f(2);
        cout << f(2);
        return 0;
    }
Discuss
Answer: (b).4
Q73.
What is the output of this program?
    #include <iostream>
    #include <cmath>
    using namespace std;
    class Complex
    {
        private:
        double real;
        double imag;
        public:
        Complex(double r = 0.0, double i = 0.0) : real(r), imag(i)
        {}
        double mag()
        {  
            return getMag();
        }
        operator double ()
        {
            return getMag();
        }
        private:
        double getMag()
        {
            return sqrt(real * real + imag * imag);
        }
    };
    int main()
    {
        Complex com(3.0, 4.0);
        cout << com.mag();
        cout << com;
        return 0
    }
Discuss
Answer: (a).5 5
Q74.
What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    class test
    {
        public:
        operator string () 
        {  
            return "Converted";
        }
    };
    int main()
    {
        test t;
        string s = t;
        cout << s << endl;
        return 0;
    }
Discuss
Answer: (a).converted
Q75.
What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
        double a = 21.09399;
        float b = 10.20;
        int c ;
        c = (int) a;
        cout << c ;
        c = (int) b;
        cout << c ;
        return 0;
    }
Discuss
Answer: (a).2110
Q76.
How types are there in user defined conversion?

a.

1

b.

2

c.

3

d.

4

Discuss
Answer: (b).2
Q77.
Pick out the correct syntax of operator conversion.
Discuss
Answer: (a).operator float()const
Discuss
Answer: (a).private and protected members of a class cannot be accessed from outside
Q79.
Which keyword is used to declare the friend function?
Discuss
Answer: (b).friend
Q80.
What is the syntax of friend function?
Discuss
Answer: (a).friend class1 Class2;

Suggested Topics

Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!