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

11/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 <stdio.h> 
#include<iostream> 
using namespace std;
int main()
{
    int x = 5, y = 5, z;
    x = ++x; y = --y;
    z = x + ++x;
    cout << z;
    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;
class B
{
	int b;
     public:
	B(){}
	B(int i){
		b = i;
	}
	int show(){
		return b;
	}
};
 
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.show()<<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 
using namespace std;
class CDummy
{
    public:
    int isitme (CDummy& param);
};
int CDummy::isitme (CDummy& param)
{
    if (¶m == this)
        return true;
    else
        return false;
}
int main ()
{
    CDummy a;
    CDummy *b = &a;
    if (b->isitme(a)) 
    {
        cout << "execute";
    }
    else
    {
        cout<<"not execute";
    }
    return 0;
}

Select an option to see the answer and solution.

How are types therein user-defined conversion?

Select an option to see the answer and solution.

What is string objects 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 A
{
	static int a;
    public:
	void show()
        {
		a++;
		cout<<"a: "<<a<<endl;
	}
};
 
int A::a = 5;
 
int main(int argc, char const *argv[])
{
	A a;
	return 0;
}

Select an option to see the answer and solution.

Pick out the other definition of objects.

Select an option to see the answer and solution.

Where does keyword ‘friend’ should be placed?

Select an option to see the answer and solution.

Which operator should be overloaded in the following code to make the program error free?
#include <iostream>
#include <string>
using namespace std;
class Box{
    int capacity;
public:
    Box(){}
    Box(double capacity){
	this->capacity = capacity;
    }
};
int main(int argc, char const *argv[])
{
    Box b1(10);
    Box b2 = Box(14);
    if(b1 == b2){
	cout<<"Equal";
    }
    else{
 	cout<<"Not Equal";
    }
    return 0;
}

Select an option to see the answer and solution.

What is a binary 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;
class numbers
{
    private:
    int m_nValues[10];
    public:
    int& operator[] (const int nValue);
};
int& numbers::operator[](const int nValue)
{
    return m_nValues[nValue];
}
int main()
{
    numbers N;
    N[5] = 4;
    cout <<  N[5];
    return 0;
}

Select an option to see the answer and solution.

Pick out the correct statement.

Select an option to see the answer and solution.

What is the return type of the conversion operator?

Select an option to see the answer and solution.

Which functions of a class are called inline functions?

Select an option to see the answer and solution.

What will happen when the function call operator is overloaded?

Select an option to see the answer and solution.

How many real types are there in complex numbers?

Select an option to see the answer and solution.

Which of these following members are not accessed by using direct member access 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 main()
{
    typedef int num;
    typedef char let;
    let w = "steve";
    num a = 10, b = 15;
    num c = a + w;
    cout << c;
    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(int argc, char const *argv[])
{
	char str[10];
	cin>>str;
	cout<<str;
	return 0;
}

Select an option to see the answer and solution.

When struct is used instead of the keyword class means, what will happen in the program?

Select an option to see the answer and solution.