Vidyalelo
C++ Programming · all questions

C++ miscellaneous
practice.

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

1,008

Questions

8/51

Page

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

Which function is used to print the maximum element from Valarray?

Select an option to see the answer and solution.

What is the use of tuple_cat() 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;
template <class T>
T max (T& a, T& b) 
{
    return (a>b?a:b);
}
int main () 
{
    int i = 5, j = 6, k;
    long l = 10, m = 5, n;
    k = max(i, j);
    n = max(l, m);
    cout << k << endl;
    cout << n << endl;
    return 0;
}

Select an option to see the answer and solution.

When will the cin can start processing of input?

Select an option to see the answer and solution.

What are Random-access Iterators?

Select an option to see the answer and solution.

How many types of loops are there in C++?

Select an option to see the answer and solution.

What does this template function indicates?
==================
template<class T>
T func(T a)
{
	cout<<a;
}
==================

Select an option to see the answer and solution.

What does the second parameter of the main function represent?

Select an option to see the answer and solution.

Which header file is used to manipulate the vector algebra in c++?

Select an option to see the answer and solution.

Which function is used to get the imaginary part of the complex number?

Select an option to see the answer and solution.

What do associate containers implement?

Select an option to see the answer and solution.

vptr is . . . . . . . .

Select an option to see the answer and solution.

What is linear_congruential_engine?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct A 
{
    private:
    int i, j, k;
    public:
    int f();
    void g();
};
int A :: f() 
{
    return i + j + k;
}
void A :: g() 
{
    i = j = k = 0;
}
class B 
{
    int i, j, k;
    public:
    int f();
    void g();
};
int B :: f() 
{
    return i + j + k; 
}
void B :: g() 
{
    i = j = k = 0;
}
int main() 
{
    A a;
    B b;
    a.f(); 
    a.g();
    b.f(); 
    b.g();
    cout << "Identical results would be produced";
}

Select an option to see the answer and solution.

Which container is best to keep the collection of distinct elements?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <cmath>
#include <list>
using namespace std;
bool same_integral_part (double first, double second)
{  
    return ( int(first) == int(second) ); 
}
struct is_near 
{
    bool operator() (double first, double second)
    { 
        return (fabs(first - second) < 5.0); 
    }
};
int main ()
{
    double mydoubles[] = { 12.15,  2.72, 73.0,  12.77,  3.14, 12.77, 73.35, 72.25, 15.3,  72.25 };
    list<double> mylist (mydoubles, mydoubles + 10);
    mylist.sort();
    mylist.unique();
    mylist.unique (same_integral_part);
    mylist.unique (is_near());
    for (list<double> :: iterator it = mylist.begin(); it != mylist.end(); ++it)
        cout << ' ' << *it;
    cout << '\n';
    return 0;
}

Select an option to see the answer and solution.

What do you mean by "No exception specification"?

Select an option to see the answer and solution.

What is a pair?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream>
#include<any>
using namespace std;
int main()
{
	float val = 5.5;
	any var(val);
    cout<<any_cast<float>(var)<<endl;
	var.reset();
	if(!var.has_value())
        {
		cout<<"var is empty\n";
	}
	else{
		cout<<"var is not empty\n";	
	}
	return 0;
}

Select an option to see the answer and solution.

Which operations don't throw anything?

Select an option to see the answer and solution.