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 24 of 39

Explore more Topics under Object Oriented Programming Using C++

Q231.
What will be the output of the following program?
#include<iostream.h> 
class BitsTest
{
    public:
    BitsTest(int &x, int &y)
    {
        x++;
        y++;
    } 
};
int main()
{
    int a = 10, b = 20;
    BitsTest objBT(a, b); 
    cout<< a << " " << b; 
    return 0; 
}
Discuss
Answer: (b).11 21
Q232.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
enum xyz
{
    a, b, c
};
int main() 
{
    int x = a, y = b, z = c;
    int &p = x, &q = y, &r = z;
    p = ++x;
    q = ++y;
    r = ++c;
    cout<< p << q << r;
    return 0;
}
Discuss
Answer: (d).It will result in a compile time error.
Q233.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int main()
{
    int arr[] = {1, 2 ,3, 4, 5}; 
    int &zarr = arr;
    for(int i = 0; i <= 4; i++)
    {
        arr[i] += arr[i];
    }
    for(i = 0; i <= 4; i++)
        cout<< zarr[i]; 
    return 0; 
}
Discuss
Answer: (d).It will result in a compile time error.
Q234.
What will be the output of the following program?
#include<iostream.h> 
struct Bits
{
    short n;
};
int main()
{
    Bits b;
    Bits& rb = b;
    b.n = 5;
    cout << b.n << " " << rb.n << " ";
    rb.n = 8;
    cout << b.n << " " << rb.n;
    return 0; 
}#include <iostream.h> 
enum xyz 
{
    a, b, c
}; 
int main()
{
    int x = a, y = b, z = c; 
    int &p = x, &q = y, &r = z; 
    p = z; 
    p = ++q;
    q = ++p;
    z = ++q + p++; 
    cout<< p << " " << q << " " << z;
    return 0; 
}
Discuss
Answer: (b).4 4 7
Q235.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int BitsFunction(int m)
{
    m *= m;
    return((10)*(m /= m)); 
}
int main()
{
    int c = 9, *d = &c, e;
    int &z = e;
    e = BitsFunction(c-- % 3 ? ++*d :(*d *= *d));
    z = z + e / 10;
    cout<< c << " " << e;
    return 0;
}#include<iostream.h> 
class Bits
{
    int x, y; 
    public:
    Bits(int x, int y)
    {
        this->x = x;
        this->y = y;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x = 50;
    int &y = x ;
    Bits b(y, x);
    return 0; 
}
Discuss
Answer: (d).The program will print nothing.
Q236.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class Compscibits
{
    int x, y; 
    public:
    void SetValue(int &xx, int &yy)
    {
        x =  xx++;
        y =  yy; 
        cout<< xx << " " << yy;
    }
};
int main()
{
    int x = 10;
    int &y = x;
    Compscibits objBits;
    objBits.SetValue(x , y);
    return 0; 
}
Discuss
Answer: (d).The program will print the output 11 11.
Q237.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class Compscibits
{
    int x, y; 
    public:
    void SetValue(int &a, int &b)
    {
        a = 100;
        x = a;
        y = b;
        Display();
    }
    void Display()
    {
        cout<< x << " " << y; 
    }
};
int main()
{
    int x = 10;
    Compscibits objBits;
    objBits.SetValue(x, x);
    return 0;
}
Discuss
Answer: (b).The program will print the output 100 100.
Q238.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class CompScibits
{
    int x, y; 
    public:
    void SetValue(int &xx, int &yy)
    {
        x =  xx ++;
        y =  yy; 
        Display();
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x = 10;
    int &y = x;
    CompScibits objBits;
    objBits.SetValue(x , y);
    return 0; 
}#include<iostream.h> 
class CompScibits
{
    int x, y; 
    public:
    CompScibits(int &xx, int &yy)
    {
        x = xx;
        y = yy;
        Display();
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x1 = 10; 
    int &p = x1;
    int y1 = 20; 
    int &q = y1; 
    CompScibits objBits(p, q); 
    return 0; 
}#include<iostream.h> 
int i, j; 
class CompScibits
{
    public:
    CompScibits(int x = 0, int y = 0)
    {
        i = x; 
        j = x; 
        Display();
    }
    void Display()
    {
        cout<< j <<" ";
    } 
}; 
int main()
{
    CompScibits objBits(10, 20); 
    int &s = i; 
    int &z = j; 
    i++;
    cout<< s-- << " " << ++z; 
    return 0; 
}
Discuss
Answer: (b).The program will print the output 10 11 11.
Q239.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int x, y; 
class BitsTest
{
    public:
    BitsTest(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;
        Display(); 
    } 
    void Display()
    {
        cout<< x << " " << y << " ";
    }
};
int main()
{
    BitsTest objBT(10, 20); 
    int &rx = x; 
    int &ry = y; 
    ry = x;
    rx = y;
    cout<< rx--; 
    return 0; 
}
Discuss
Answer: (b).The program will print the output 10 20 10.
Q240.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class Compscibits
{
    int a, b, c; 
    public:
    void SetValue(int x, int y ,int z)
    {
        a = x;
        b = y;
        c = z;
    } 
    void Display()
    {
        cout<< a << " " << b << " " << c;
    } 
}; 
int main()
{
    Compscibits objBits;
    int x  = 2;
    int &y = x;
    y = 5;
    objBits.SetValue(x, ++y, x + y);
    objBits.Display();
    return 0; 
}
Discuss
Answer: (b).The program will print the output 6 6 10.

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!