Vidyalelo
C++ Programming · all questions

Classes and Objects in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

251

Questions

6/13

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    typedef int num;
    num a = 10, b = 15;
    num c = a + b + a - b;
    cout << c;
    return 0;
}

Select an option to see the answer and solution.

Pick out the correct syntax of operator conversion.

Select an option to see the answer and solution.

What are the essential operators in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class B
{
	int b;
   public:
	B(int i){
		b = i;
	}
};
 
class C
{
	B b;
    public:
	C(int i){
		b = B(i);
	}
	friend void show();
};
 
void show()
{
	C c(10);
	cout<<"value of b is: "<<c.b.b<<endl;
}
 
int main(int argc, char const *argv[])
{
	show();
	return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string str ("nobody does like this");
    string key ("nobody");
    size_t f;
    f = str.rfind(key);
    if (f != string::npos)
        str.replace (f, key.length(), "everybody");
    cout << str << endl;
    return 0;
}

Select an option to see the answer and solution.

What is the correct syntax of accessing a static member of a Class?
---------------------------
Example class:
class A
{
	public:
		static int value;
}
---------------------------

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class myclass
{
    public:
    int i;
    myclass *operator->()
    {return this;}
};
int main()
{
    myclass ob;
    ob->i = 10; 
    cout << ob.i << " " << ob->i;
    return 0;
}

Select an option to see the answer and solution.

What is the syntax of user-defined data types?

Select an option to see the answer and solution.

Which is used to pass the large objects in c++?

Select an option to see the answer and solution.

How to stop your program from eating so much ram?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
    complex<double> c_double(2, 3);
    complex<int> c_int(4, 5);
    c_double *= 2;
    c_double = c_int;
    cout << c_double;
    return 0;
}

Select an option to see the answer and solution.

Operator overloading is . . . . . . . .

Select an option to see the answer and solution.

What do we need to do to pointer for overloading the subscript operator?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int operate (int a, int b)
{
    return (a * b);
}
float operate (float a, float b)
{
    return (a / b);
}
int main ()
{
    int x = 5, y = 2;
    float n = 5.0, m = 2.0;
    cout << operate (x, y);
    cout << operate (n, m);
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Box
{
    public :
    double length;
    double breadth;
    double height;
};
int main( )
{
    Box Box1;
    double volume;
    Box1.height = 5;
    Box1.length = 6;
    Box1.breadth = 7.1;
    volume = Box1.height * Box1.length * Box1.breadth;
    cout << "Volume of Box1 : " << volume <<endl;
    return 0;
}

Select an option to see the answer and solution.

Pick out the compound assignment statement.

Select an option to see the answer and solution.

Identify the correct statement.

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample 
{
    int width, height;
    public:
    void set_values (int, int);
    int area () {return (width * height);}
    friend sample duplicate (sample);
};
void sample::set_values (int a, int b) 
{
    width = a;
    height = b;
}
sample duplicate (sample rectparam)
{
    sample rectres;
    rectres.width = rectparam.width * 2;
    rectres.height = rectparam.height * 2;
    return (rectres);
}  
int main ()  
{
    sample rect, rectb;
    rect.set_values (2, 3);
    rectb = duplicate (rect);
    cout << rectb.area();
    return 0;
}

Select an option to see the answer and solution.

What is the use of function call operator?

Select an option to see the answer and solution.

Pick the incorrect statement about inline functions in C++?

Select an option to see the answer and solution.