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

15/51

Page

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

What will be the output of the following C++ code?
#include <iostream>
#include <iterator>
using namespace std;
int main ()
{
    try {
        double value1, value2;
        istream_iterator<double> eos;       
        istream_iterator<double> iit (cin);   
        if (iit != eos) 
            value1 = *iit;
        iit++;
        if (iit != eos) 
            value2 = *iit;
        cout << (value1 * value2) << endl;
    }
    catch (...) {
        cout << "Unknown exception: " << endl;
    }
    return 0;
}

Select an option to see the answer and solution.

Which is called on allocating the memory for the array of objects?

Select an option to see the answer and solution.

What will be the type of output of vector cross product?

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 <int>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.

Which keyword is used to declare the min and max functions?

Select an option to see the answer and solution.

What is the syntax of inheritance of class?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
int main ()
{
    FILE * p;
    int c;
    int n = 0;
    p = fopen ("myfile.txt", "r");
    if (p == NULL) 
        perror ("Error opening file");
    else
    {
        do {
            c = getc (p);
            if (c == '$') 
                n++;
        } while (c != EOF);
        fclose (p);
        printf ("%d\n", n);
    }
    return 0;
}

Select an option to see the answer and solution.

Which function is used to check whether a character is printable on console?

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;
bool myfunction (int i,int j) { return (i<j); }
int main () 
{
    int myints[] = {9, 8, 7, 6, 5};
    vector<int> myvector (myints, myints + 5);
    partial_sort (myvector.begin(), myvector.begin() + 3, myvector.end());
    partial_sort (myvector.begin(), myvector.begin() + 2, myvector.end(), 
    myfunction);
    for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

What may be the name of the parameter that the template should take?

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;
 
bool IsOdd (int i) 
{ 
	return (i%2)==1; 
}
 
int main () 
{
  vector<int> v;
 
  for (int i=1; i<=10; ++i) 
  	v.push_back(i);
 
  vector<int>::iterator bound;
  bound = partition (v.begin(), v.end(), IsOdd);
 
  for (vector<int>::iterator it=v.begin(); it!=bound; ++it)
    cout << ' ' << *it;
  cout << '\n';
 
  for (vector<int>::iterator it=bound; it!=v.end(); ++it)
    cout << ' ' << *it;
  cout << '\n';
 
  return 0;
}

Select an option to see the answer and solution.

Which of the following is correct about the second parameter of the main function?

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, 5.0);
	cout<<"Complex number with magnitude "<<abs(cn)<<" 
        and phase angle "<<arg(cn)<<" is: 
        "<<polar(abs(cn), arg(cn))<<endl;
	return 0;
}

Select an option to see the answer and solution.

How many types of container classes 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 <algorithm>
#include <vector>
using namespace std;
bool IsOdd (int i) 
{
    return (i % 2) == 1; 
}
int main () 
{
    vector<int> myvector;
    for (int i = 1; i < 10; ++i) myvector.push_back(i);
    vector<int> :: iterator bound;
    bound = partition (myvector.begin(), myvector.end(), IsOdd);
    for (vector<int> :: iterator it = myvector.begin(); it != bound; ++it)
        cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

Which header file is required to use complex class in your program?

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()
{
    int ran = rand();
    cout << ran << endl;
}

Select an option to see the answer and solution.

Which of the following is correct about shift() and cshift()?
1. shift() makes some values of Valarray equal to 0 after shifting by a non-zero number
2. cshift() makes some values of Valarray equal to 0 after shifting by a non-zero number

Select an option to see the answer and solution.

What kind of object is modifying sequence algorithm?

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 n;
    n = -77;
    cout.width(4); 
    cout << internal << n << endl;
    return 0;
}

Select an option to see the answer and solution.