What happens when you attempt to compile and run the following code? #include <string> #include <list> #include <iostream> using namespace std; template<class T> void print(T start, T end) { while (start != end) { std::cout << *start << " "; start++; } } int main() { string t1[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; list<string> l1(t1, t1 + 10); list<string> l2(l1); l2.reverse(); l1.splice(l1.end(),l2); l1.unique(); print(l1.begin(), l1.end()); cout<<endl; return 0; }
Answer(s): B
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int t[] = {1,2,3,4,5,1,2,3,5,4}; vector<int> v (t,t+10); vector<int>::iterator it; int m1[] = {1, 3, 2}; it = find_end (v.begin(), v.end(), m1, m1+3); if (it != v.end()) cout << "Found at position: " << it?v.begin() << endl; return 0; }
Answer(s): C
What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3? #include <iostream> #include <fstream> #include <string> #include <list> #include <algorithm> using namespace std; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) {out<<val<<" "; } }; int main () { ifstream f("test.in"); list<int> l; for( ; f.good() ; ) { int i; f>>i; l.push_back(i); } f.close(); for_each(l.begin(), l.end(), Out<int>(cout)); return 0; }Program will output:
Answer(s): A
What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> int main () { int t[]={1,2,3,4,5}; std::vector<int> v1(t,t+5); std::vector<int> v2(v1); v1.resize(10); v2.reserve(10); std::vector<int>::iterator i = v1.begin(); int ii = 0; while (i != v1.end()) { std::cout<<i[ii]<<" ";ii??;i++; } i = v2.begin();ii=0; while (i != v2.end()) { std::cout<<i[ii]<<" ";ii??;i++; } return 0; }
What will happen when you attempt to compile and run the following code? #include <iostream> using namespace std; template <class T> class A { T _v; public: A(T v); }; template<class T> A::A(T v):_v(v) {} int main() { A<int> a(2); cout<<1<<endl; return 0; }
Post your Comments and Discuss C++ Institute CPP exam prep with other Community members:
Our website is free, but we have to fight against AI bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the CPP content, but please register or login to continue.