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

16/51

Page

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

What is the use of clog?

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 <typename T = float, int count = 3>
T multIt(T x)
{
    for(int ii = 0; ii < count; ii++)
    {
        x = x * x;
    }
    return x;
};
int main()
{
    float xx = 2.1;
    cout << xx << ": " << multIt<>(xx) << endl;
}

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 = 5;
    auto check = [=]() 
    {
	a = 10;
    };
    check();
    cout<<"Value of a: "<<a<<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 <algorithm>
#include <vector>
using namespace std;
int main () 
{
    vector<int> first (5, 10);
    vector<int> second (5, 33);
    vector<int>::iterator it;
    swap_ranges(first.begin() + 1, first.end() - 1, second.begin());
    cout << " first contains:";
    for (it = first.begin(); it != first.end(); ++it)
        cout << " " << *it;
    cout << "\nsecond contains:";
    for (it = second.begin(); it != second.end(); ++it)
        cout << " " << *it;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <vector>
#include <iostream>
#include <typeinfo>
#include <stdexcept>
using namespace std;
int main()
{
    vector<int> vec;
    vec.push_back(10);
    int i = vec[100];
    try {
        i = vec[0];
        cout << i << endl;
    }
    catch (exception &e)
    {
        cout << "Caught: " << e.what( ) << endl;
        cout << "Type: " << typeid( e ).name( ) << endl;
    }
    catch (...) 
    {
        cout << "Unknown exception: " << endl;
    }
    return 0;
}

Select an option to see the answer and solution.

What is the use of the 'finally' keyword?

Select an option to see the answer and solution.

Which mathematics library is used for vector manipulation in c++?

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>
#include <utility>
using namespace std;
bool mypredicate (int i, int j)
{
    return (i == j);
}
int main () 
{
    vector<int> myvector;
    for (int i = 1; i < 6; i++) myvector.push_back (i * 10);
    int myints[] = {10, 20, 30, 40, 1024};
    pair<vector<int> :: iterator, int*> mypair;
    mypair = mismatch (myvector.begin(), myvector.end(), myints);
    cout  << *mypair.first<<'\n';
    cout  << *mypair.second << '\n';
    ++mypair.first; ++mypair.second;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <memory>
#include <string>
using namespace std;
int main () 
{
    pair <string*, ptrdiff_t>
    result = get_temporary_buffer<string>(3);
    if (result.second > 0)
    {
        uninitialized_fill ( result.first, result.first + result.second, 
        "Hai" );
        for (int i=0; i<result.second; i++)
            cout << result.first[i] ;
        return_temporary_buffer(result.first);
    }
    return 0;
}

Select an option to see the answer and solution.

What is the correct syntax of constructing any using parameterized constructor?

Select an option to see the answer and solution.

Which of the following operator is used to capture all the external variable by value?

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( )
{
    char line[100];
    cin.getline( line, 100, 't' );
    cout << line;
    return 0;
}

Select an option to see the answer and solution.

How many types of inheritance are there in c++?

Select an option to see the answer and solution.

Which of the following function is used to initialize a tuple?

Select an option to see the answer and solution.

Which of the following header file is required to use in-bulit functors of 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[27] = "abcdefghijklmnopqrstuvwxyz";
    for(int i=0;i<27;i++)
    {
	cout<<(bool)isxdigit(arr[i]);
    }
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream> 
#include <vector> 
 
using namespace std; 
 
int main() 
{ 
    vector<int> v; 
 
    for (int i = 1; i <= 5; i++) 
        v.push_back(i); 
 
    cout<<v.size();
    cout<<endl<<v.capacity();  
    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;
template <class type>
class Test
{
    public:
    Test()
    {
    };
    ~Test()
    {  
    };
    type Funct1(type Var1)
    {
        return Var1;
    }
    type Funct2(type Var2)
    {
        return Var2;
    }
};
int main()
{
    Test<int> Var1;
    Test<double> Var2;
    cout << Var1.Funct1(200);
    cout << Var2.Funct2(3.123);
    return 0;
}

Select an option to see the answer and solution.

Which header file is used to create the pseudo random generator?

Select an option to see the answer and solution.

How many kind of operation can be applied to transform method in c++?

Select an option to see the answer and solution.