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

19/51

Page

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

How many parameters does a operator() in a function object shoud 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 <double> cn(3.0, 4.0);
	cout<<"Norm is: "<<norm(cn)<<endl;
	return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
    cout << RAND_MAX << endl;
}

Select an option to see the answer and solution.

Which of the following is correct about remove_all_extents() function?

Select an option to see the answer and solution.

What is the use of includes function in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char const *argv[])
{
    char arr[12] = "H3ll0\tW0r1d";
    for(int i=0;i<12;i++)
    {
	cout<<(bool)iscntrl(arr[i]);
    }
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main ()
{
    int numbers[] = {10, -20, -30, 40, -50};
    int cx;
    cx = count_if ( numbers, numbers + 5, bind2nd(less<int>(), 0) );
    cout << cx;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
	bitset<8> b1(95);
	bitset<8> b2(46);
	cout<<(b1^b2);
}

Select an option to see the answer and solution.

If i1 is Input Iterator and i2 is Output Iterator, then which of the following things are correct?
i) cout<<*i1;
ii) i2 can be used with == operator
iii) *i1 = 1
iv) i2--

Select an option to see the answer and solution.

Identify the incorrect statement.

Select an option to see the answer and solution.

To what kind of elements does non-modifying sequence algorithm can be applied?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () 
{
    int myints[] = { 10, 20, 30 ,40 };
    int * p;
    p = find (myints, myints + 4, 30);
    --p;
    cout << *p << '\n';
    return 0;
}

Select an option to see the answer and solution.

Which container is used to store elements as key-value pair?

Select an option to see the answer and solution.

What is the use of has_value() function in any container?

Select an option to see the answer and solution.

Which of the following header files is required for creating and reading data files?

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 
{
    int i;
    char j;
    float f;
    void func();
};
void A :: func() {}
struct B 
{
    public:
    int i;
    char j;
    float f;
    void func();
};
void B :: func() {}
int main() 
{
    A a; B b;
    a.i = b.i = 1; 
    a.j = b.j = 'c';
    a.f = b.f = 3.14159;
    a.func();
    b.func();
    cout << "Allocated"; 
    return 0;
}

Select an option to see the answer and solution.

Which function allows you to set minimum width for the next input?

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>
inline T square(T x)
{
    T result;
    result = x * x;
    return result;
};
template <>
string square<string>(string ss)
{
    return (ss+ss);
};
int main()
{
    int i = 2, ii;
    string ww("A");
    ii = square<int>(i);
    cout << i << ": " << ii;
    cout << square<string>(ww) << ":" << endl;
}

Select an option to see the answer and solution.

How many categories of iterators are there 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>
#include <cstdlib>
using namespace std;
template<class T>
class A
{
    public:
	T func(T a, T b){
		return a/b;
	}	
};
 
int main(int argc, char const *argv[])
{
	A <float>a1;
	cout<<a1.func(3,2)<<endl;
	cout<<a1.func(3.0,2.0)<<endl;
	return 0;
}

Select an option to see the answer and solution.