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

30/51

Page

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

What does the size of the vector refers to in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <array>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
	array<int, 10> arr1 = {1,2,3,4,5};
	array<int, 5> arr2 = {6,7,8,9,10};
	arr1.swap(arr2);
	for(int i=0;i<5;i++)
		cout<<arr1[i]<<" ";
	cout<<endl;
	for(int i=0;i<5;i++)
		cout<<arr2[i]<<" ";
	cout<<endl;
	return 0;
}

Select an option to see the answer and solution.

Which function is used to check whether a character is hexadecimal?

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 vec
{
    public:
    vec(float f1, float f2) 
    {
        x = f1;
        y = f2;
    }
    vec()
    {
    }
    float x;
    float y;
};
vec addvectors(vec v1, vec v2);
int main() 
{
    vec v1(3, 6);
    vec v2(2, -2);
    vec v3 = addvectors(v1, v2);
    cout << v3.x << ", " << v3.y << endl;
}
vec addvectors(vec v1, vec v2)
{
    vec result;
    result.x = v1.x + v2.x;
    result.y = v1.y + v2.y;
    return result;
};

Select an option to see the answer and solution.

The destination statement for the goto label is identified by what label?

Select an option to see the answer and solution.

Given below classes which of the following are the possible row entries in vtable of D2 class?
class Base
{
    public:
    virtual void function1() {};
    virtual void function2() {};
};
class D1: public Base
{
    public:
    virtual void function1() {};
};
class D2: public Base
{
    public:
    virtual void function2() {};
};

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 str[] = "Steve jobs";
    int val = 65;
    char ch = 'A';
    cout.width (5);
    cout << right;
    cout << val << endl;
    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 T>
T max (T &a, T &b)
{
	cout << "Template Called ";
    return (a > b)? a : b;
}
 
template <>
int max <int> (int &a, int &b)
{
    cout << "Called ";
    return (a > b)? a : b;
}
 
int main ()
{
    int a = 10, b = 20;
    cout << max <int> (a, b);
}

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
{
	int a;
   public:
	virtual void func() = 0;
};
 
class B: public A
{
   public:
	void func(){
		cout<<"Class B"<<endl;
	}	
};
 
int main(int argc, char const *argv[])
{
	A a;
	a.func();
	return 0;
}

Select an option to see the answer and solution.

To use command line arguments in C++, how many parameters are passed to the main function?

Select an option to see the answer and solution.

What is the correct syntax of declaring an array class?

Select an option to see the answer and solution.

Which is similar to template specialization?

Select an option to see the answer and solution.

Pick the correct statement.

Select an option to see the answer and solution.

Pick out the correct statement about sequence point.

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 Base
{
    public:
    virtual void print() const = 0;
};
class DerivedOne : virtual public Base
{
    public:
    void print() const
    {
        cout << "1";
    }
};
class DerivedTwo : virtual public Base
{
    public:
    void print() const
    {
        cout << "2";
    }
};
class Multiple : public DerivedOne, DerivedTwo
{
    public:
    void print() const
    {
        DerivedTwo::print();
    }
};
int main()
{
    Multiple both;
    DerivedOne one;
    DerivedTwo two;
    Base *array[ 3 ];
    array[ 0 ] = &both;
    array[ 1 ] = &one;
    array[ 2 ] = &two;
    for ( int i = 0; i < 3; i++ )
    array[ i ] -> print();
    return 0;
}

Select an option to see the answer and solution.

What happens when only one argument is supplied to reset() function?

Select an option to see the answer and solution.

Which of the follwoing function(s) of Array classes are similar to [] operator?

Select an option to see the answer and solution.

Where does the vector add the item?

Select an option to see the answer and solution.

What is the name of the myfile2 file after executing the following C++ code?
#include <stdio.h>
int main ()
{
    int result;
    char oldname[] = "myfile2.txt";
    char newname[] = "newname.txt";
    result = rename(oldname, newname );
    if (result == 0)
        puts ( "success" );
    else
        perror( "Error" );
    return 0;
}

Select an option to see the answer and solution.

Which type of relationship is modelled by Association?

Select an option to see the answer and solution.