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

12/13

Page

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

Pick the incorrect statement about Character-Array.

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 x = 5, y = 5, z;
    x = ++x; y = --y;
    z = x++ + y--;
    cout << z;
    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 num1 = 5;
    int num2 = 3;
    int num3 = 2;
    num1 = num2++;
    num2 = --num3;
    cout << num1 << num2 << num3;
    return 0;
}

Select an option to see the answer and solution.

Which of the following is correct way of concatenating two string objects in C++?
way 1:
string s1 = "hello";
string s2 = "world";
string s3 = s1 + s2;
 
way 2:
string s1 = "hello";
string s2 = "world";
string s3 = s1.append(s2);
 
way 3:
string s1 = "hello";
string s2 = "world";
string s3 = strcat(s1,s2);

Select an option to see the answer and solution.

What does the data type defined by union will do?

Select an option to see the answer and solution.

What is the name of | operator?

Select an option to see the answer and solution.

In which direction does the assignment operation will take place?

Select an option to see the answer and solution.

Which category of data type a class belongs to?

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 a, b;
    public:
    void test()
    {
        a = 100;
        b = 200;
    }
    friend int compute(sample e1);
};
int compute(sample e1)
{
    return int(e1.a + e1.b) - 5;
}
int main()
{
    sample e;
    e.test();
    cout  << compute(e);
    return 0;
}

Select an option to see the answer and solution.

Which operator works only with integer variables?

Select an option to see the answer and solution.

What does a class in C++ holds?

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[])
{
	string str;
	cin>>str;
	cout<<str;
	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
{
	mutable 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 is the size of the heap?

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 ("helloworld.");
  cout << str.substr(3).substr(4) << endl;
  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[] = "Hello World";
	cout<<str[0];
	return 0;
}

Select an option to see the answer and solution.

Pick the correct statement about string objects in C++.

Select an option to see the answer and solution.

Why we use the "dynamic_cast" type conversion?

Select an option to see the answer and solution.

Which is used to return the number of characters in the string?

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 = 0;
    int b = 10;
    if ( a && b )
    {
        cout << "true"<< endl ;
    }
    else
    {
         cout << "false"<< endl ;
    }
    return 0;
}

Select an option to see the answer and solution.