1. What is the use of clog?
2. 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;
}
#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;
}
3. 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;
}
#include<iostream>
using namespace std;
int main()
{
int a = 5;
auto check = [=]()
{
a = 10;
};
check();
cout<<"Value of a: "<<a<<endl;
return 0;
}
4. 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;
}
#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;
}
5. 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;
}
#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;
}
6. What is the use of the 'finally' keyword?
7. Which mathematics library is used for vector manipulation in c++?
8. 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;
}
#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;
}
9. 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;
}
#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;
}
10. What is the correct syntax of constructing any using parameterized constructor?
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 5
- C plus plus miscellaneous - Section 6
- 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