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

3/13

Page

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

Which of the following operator cannot be overloaded?

Select an option to see the answer and solution.

Pick the correct statement.

Select an option to see the answer and solution.

Which is used to define the member of a class externally?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
ostream & operator<<(ostream & i, int n)
{
    return i;
}
int main()
{
    cout << 5 << endl;
    cin.get();
    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 Box{
    int capacity;
    bool operator<(Box b){
	return this->capacity < b.capacity ? true : false;
    }
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<<"Box 2 has large capacity.";
    }
   else{
	cout<<"Box 1 has large capacity.";
    }
    return 0;
}

Select an option to see the answer and solution.

Which operator a pointer object of a class uses to access its data members and member functions?

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;         
    a = 10;           
    b = 4;            
    a = b;           
    b = 7;           
    cout << "a:";
    cout << a;
    cout << " b:";
    cout << b;
    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 ()
{
  std::string str ("Example.");
  str.back() = '!';
  std::cout << str << endl;
  return 0;
}

Select an option to see the answer and solution.

Which is the correct example of a unary operator?

Select an option to see the answer and solution.

In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?

Select an option to see the answer and solution.

Which of the following operator can be overloaded?

Select an option to see the answer and solution.

How to store the large objects in c++ if it extends its allocated memory?

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");
    string::reverse_iterator r;
    for (r = str.rbegin() ; r < str.rend(); r++ )
        cout << *r;
    return 0;
}

Select an option to see the answer and solution.

How to declare the complex number?

Select an option to see the answer and solution.

Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result?
#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<<"Box 2 has large capacity.";
    }
    else{
	cout<<"Box 1 has large capacity.";
	}
    return 0;
}

Options are not available for this question.

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(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;
}

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 ("example.");
  str.front() = 'E';
  cout << str << endl;
  return 0;
}

Select an option to see the answer and solution.

Which container in c++ will take large objects?

Select an option to see the answer and solution.

How many types of models are available to create the user-defined data type?

Select an option to see the answer and solution.

Which concepts does the Pre Increment use?

Select an option to see the answer and solution.