C++ Institute certification practice

CPP Practice Questions

Try 10 free CPP exam-style questions for C++ Institute CPP Certified Professional Programmer. Check each answer and review the explanation and source references.

Exam code
CPP
Provider
C++ Institute
Free questions
10
Full set
228 questions
Last update check

Looking to ace the CPP certification? Cert Mage provides a top-tier practice questions loaded with accurate study materials to help you get there. Our advanced exam simulator lets you experience the actual test environment, ensuring you know exactly what to expect. Within our comprehensive CPP question bank, you will find meticulously updated content. You can easily test your baseline knowledge by taking our free CPP sample questions today. When you feel confident, unlock our complete set of CPP practice questions and verified exam questions to guarantee a winning score.

What happens when you attempt to compile and run the following code? #include #include #include using namespace std; templatestruct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { int t1[]={3,2,4,1,5}; int t2[]={5,6,8,2,1}; vector v1(10); sort(t1, t1+5); sort(t2, t2+5); set_symmetric_difference(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.end(), Out(cout));cout<<endl; return 0; } Program outputs:
Answer options
What happens when you attempt to compile and run the following code? #include #include #include 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; } bool operator==(const A & b) const { return a == b.a; } }; bool compare(const A & a, const A & b) { return a == b; } int main () { int t[] = {1,2,3,3,5,1,2,4,4,5}; vector v (t,t+10); vector::iterator it = v.begin(); while ( (it = adjacent_find (it, v.end(), compare)) != v.end()) { cout<<it?v.begin()<<" ";it++; } cout<< endl; return 0; }
Answer options
What happens when you attempt to compile and run the following code? #include #include using namespace std; bool mycomparison (int first, int second){return first>second;} template void print(T start, T end) { while (start != end) { std::cout << *start << " "; start++; } } int main() { int t1[] ={ 1, 7, 8, 4, 5 }; list l1(t1, t1 + 5); int t2[] ={ 3, 2, 6, 9, 0 }; list l2(t2, t2 + 5); l1.sort(mycomparison); l2.sort(mycomparison); l1.merge(l2,mycomparison); print(l1.begin(), l1.end()); print(l2.begin(), l2.end()); cout<<endl; return 0; }
Answer options
What happens when you attempt to compile and run the following code? #include #include #include #include using namespace std; class B { int val; public: B(int v):val(v){} B(){} int getV() const {return val;} bool operator > (const B & v) const { return val>v.val;} }; ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} templatestruct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque d1(t, t+10); sort(d1.begin(), d1.end(), greater()); deque::iterator it = lower_bound(d1.begin(), d1.end(), 4,greater()); for_each(it, d1.end(), Out(cout));cout<<endl; return 0; } Program outputs:
Answer options
What happens when you attempt to compile and run the following code? #include #include using namespace std; class A { int a,b; public: A(const A & c) { a = c.a; } A():a(0),b(0){} void setA(int a) {this?>a = a;} void setB(int b) {this?>b = b;} int getA() {return a;} int getB() {return b;} }; int main () { vectorv; A a; a.setA(10); a.setB(11); v.push_back(a); cout<<v[0].getB()<<" "<<v[0].getA()<<endl; return 0; }
Answer options
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three? #include #include using namespace std; int main () { string a; cin.getline(a); cout<<a<<endl; return 0; } Program will output:
Answer options
What happens when you attempt to compile and run the following code? #include #include #include using namespace std; class B { int val; public: B(int v):val(v){} int getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; templatestruct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; int main() { B t1[]={3,2,4,1,5}; B t2[]={5,6,8,2,1}; vector v1(10,0); sort(t1, t1+5); sort(t2, t2+5); set_difference(t1,t1+5,t2,t2+5,v1.begin()); for_each(v1.begin(), v1.end(), Out(cout));cout<<endl; return 0; } Program outputs:
Answer options
Which lines of the code below contain proper instantiation of queue objects? #include #include #include #include #include using namespace std; int main() { deque mydeck; list mylist; vector myvector; queue first; // line I queue second(mydeck);// line II queue third(second);// line III queue fourth(mylist);// line IV queue fifth(myvector);// line V return 0; }
Answer options
What happens when you attempt to compile and run the following code? #include #include #include 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; } operator int() const {return a;} }; int main () { int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5}; set s (t,t+15); cout<<equal(s.begin(), s.end(), t)<<endl; return 0; } Program outputs:
Answer options
What will happen when you attempt to compile and run the following code? #include #include using namespace std; template class A { T_v; public: A() {} A(T v): _v(v){} T getV() { return _v; } void add(T & a) { _v+=a; } }; int main() { Aa("Hello"); string s(" world!"); a.add(s); cout << a.getV() <<endl; return 0; }
Answer options
Question 1 of 10

Source context

How this practice set is maintained

Maintained by the CertMage content team, this page loads questions from the exam dataset connected to its preparation resource. When an answer includes a supporting reference, it is shown with that answer so you can review the underlying vendor documentation.

Certification objectives, interfaces, and vendor services can change. Verify important details against the provider's current exam guide and documentation before your exam.

Scroll to Top