11. Which of the following function is used to get the actual number of elements stored in vector?
12. What are functors in C++?
13. How many streams are automatically created when executing a program?
14. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector (3);
for (unsigned i = 0; i < myvector.size(); i++)
myvector.at(i) = i;
for (unsigned i = 0; i < myvector.size(); i++)
cout << ' ' << myvector.at(i);
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector (3);
for (unsigned i = 0; i < myvector.size(); i++)
myvector.at(i) = i;
for (unsigned i = 0; i < myvector.size(); i++)
cout << ' ' << myvector.at(i);
return 0;
}15. What is the use of is_array() function in C++?
16. What will be the output of the following C++ code?
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int i, n;
int * p;
i = 2;
p= new (nothrow) int[i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
p[n] = 5;
}
for (n = 0; n < i; n++)
cout << p[n];
delete[] p;
}
return 0;
}
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int i, n;
int * p;
i = 2;
p= new (nothrow) int[i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
p[n] = 5;
}
for (n = 0; n < i; n++)
cout << p[n];
delete[] p;
}
return 0;
}17. What is the correct syntax of defining function template/template functions?
18. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
long factorial (long a)
{
if (a > 1)
return (a * factorial (a + 1));
else
return (1);
}
int main ()
{
long num = 3;
cout << num << "! = " << factorial ( num );
return 0;
}
#include <iostream>
using namespace std;
long factorial (long a)
{
if (a > 1)
return (a * factorial (a + 1));
else
return (1);
}
int main ()
{
long num = 3;
cout << num << "! = " << factorial ( num );
return 0;
}19. What will be the output of the following C++ code?
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
int square(int i) { return i * i; }
int main()
{
vector<int> V, V2;
V.push_back(0);
V.push_back(1);
V.push_back(2);
transform(V.begin(), V.end(), back_inserter(V2), square);
copy(V2.begin(), V2.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
int square(int i) { return i * i; }
int main()
{
vector<int> V, V2;
V.push_back(0);
V.push_back(1);
V.push_back(2);
transform(V.begin(), V.end(), back_inserter(V2), square);
copy(V2.begin(), V2.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}20. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class BaseClass
{
int x;
public:
void setx(int n)
{
x = n;
}
void showx()
{
cout << x ;
}
};
class DerivedClass : private BaseClass
{
int y;
public:
void setxy(int n, int m)
{
setx(n);
y = m;
}
void showxy()
{
showx();
cout << y << '\n';
}
};
int main()
{
DerivedClass ob;
ob.setxy(10, 20);
ob.showxy();
return 0;
}
#include <iostream>
using namespace std;
class BaseClass
{
int x;
public:
void setx(int n)
{
x = n;
}
void showx()
{
cout << x ;
}
};
class DerivedClass : private BaseClass
{
int y;
public:
void setxy(int n, int m)
{
setx(n);
y = m;
}
void showxy()
{
showx();
cout << y << '\n';
}
};
int main()
{
DerivedClass ob;
ob.setxy(10, 20);
ob.showxy();
return 0;
}Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
