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

10/13

Page

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

Which of the following is not a modifier function in string class?

Select an option to see the answer and solution.

In the case of friend operator overloaded functions how many maximum object arguments a unary operator overloaded function can take?

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<int> i(2, 3);
    i = i * 6 / 3;
    cout << i;
    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 sample
{
    public:
    sample() 
    {  
        cout << "X::X()" << endl; 
    }
    sample( sample const & ) 
    {  
        cout << "X::X( X const & )" << endl;
    }
    sample& operator=( sample const & )
    { 
        cout << "X::operator=(X const &)" << endl;
    }
};
sample f() 
{
    sample tmp;
    return tmp;
}
int main() 
{
    sample x = f();
    return 0;
}

Select an option to see the answer and solution.

Which of the following operators can't be overloaded?

Select an option to see the answer and solution.

Which of the following statements is NOT valid about operator overloading?

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 ()
{
    int a, b, c;
    a = 2;
    b = 7;
    c = (a > b) ? a : b;
    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>
using namespace std;
class Distance
{
    private:
    int feet;
    int inches;
    public:
    Distance()
    {
        feet = 0;
        inches = 0;
    }
    Distance(int f, int i) 
    {
        feet = f;
        inches = i;
    }
    Distance operator()(int a, int b, int c)
    {
        Distance D;
        D.feet = a + c + 10;
        D.inches = b + c + 100 ;
        return D;
    }
    void displayDistance()
    {
        cout  << feet <<  inches << endl;
    }
};
int main()
{
    Distance D1(11, 10), D2;
    cout << "First Distance : ";
    D1.displayDistance();
    D2 = D1(10, 10, 10);
    cout << "Second Distance :";
    D2.displayDistance();
    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 A
{
	int a = 5;
    public:
	void change(int i){
		a = i;
	}
	static void value_of_a(){
		cout<<a;
	}
};
 
int main(int argc, char const *argv[])
{
	A a1 = A();
	a1.change(10);
	a1.value_of_a();
	return 0;
}

Select an option to see the answer and solution.

Where does the object is created?

Select an option to see the answer and solution.

subscript operator is used to access which elements?

Select an option to see the answer and solution.

Which keyword is used to represent a friend function?

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
{
    private:
    int var;
    public:
    void input()
    {
       cout << var;
    }
    void output()
    {
       cout << "Variable entered is ";
       cout << var << "\n";
    }
};
int main()
{
    sample object;
    object.input();
    object.output();
    object.var();
    return 0;
}

Select an option to see the answer and solution.

What is Character-Array?

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 Box
{
	int capacity;
    public:
	Box(int cap){
		capacity = cap;
	}
 
	friend void show();
};
 
void show()
{	
	Box b(10);
	cout<<"Value of capacity is: "<<b.capacity<<endl;
}
 
int main(int argc, char const *argv[])
{
	show();
	return 0;
}

Select an option to see the answer and solution.

Pick the incorrect statements out of the following.

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
{
	int a;
 
   public:
	int assign(int i) const {
		a = i;
	}
	int return_value() const {
		return a;
	}
};
int main(int argc, char const *argv[])
{
	A obj;
	obj.assign(5);
	cout<<obj.return_value();
}

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 ("Microsoft");
    for (size_t i = 0; i < str.length();)
    {
        cout << str.at(i-1);
    }
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h> 
#include<iostream>
using namespace std;
int main()
{
    int a = 21;
    int c ;
    c = a++;
    cout << c;  
    return 0;
}

Select an option to see the answer and solution.

Which keyword is used to define the user defined data types?

Select an option to see the answer and solution.