What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <deque> using namespace std; class A { int a; public: A(int a) : a(a) {} int getA() const { return a; } void setA(int a) { this?>a = a; } }; int main () { int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5}; deque<int> d (t,t+15); int number = count(d.begin(), d.end(), 2); cout<< number<<endl; return 0; }Program outputs:
Answer(s): A
What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> int main () { std::vector<int> v1; for(int i = 10; i>0; i??) { v1.push_back(i); } std::vector<int>::iterator it = v1.begin(); int sum = 0; while(it != v1.end()) { sum+=it++; } std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<<sum <<std::endl; return 0; }
Answer(s): B
What happens when you attempt to compile and run the following code? include <iostream> #include <algorithm> #include <vector> #include <deque> #include <set> using namespace std; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector<int> v1(t, t + 10); deque<int> d1(t, t + 10); set<int> s1(t, t + 10); cout<<find(v1.begin(), v1.end(), 6)<<" "<<find(d1.begin(), d1.end(), 6)<<" "<<find(s1.begin(), s1.end(), 6); return 0; }
Answer(s): D
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; template <typename T> class A { T _v; public: A() {} A(T v): _v(v){} T getV() { return _v; } void add(T a) { _v+=a; } template <class U> U get(U a) { return (U)(_v); } }; int main() { A<int> a(1); a.add(10); cout.setf( ios::showpoint); cout << a.getV() << " " << a.get(1.0)<<endl; return 0; }
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void g(int a) { cout<<a?1<<endl; } template<class A> void g(A a) { cout<<a+1<<endl; } int main() { int a = 1; g(a); 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.