All Practice Exams

100+ Free C++ CPP Practice Questions

Pass your C++ Institute Certified Professional Programmer exam on the first try — instant access, no signup required.

✓ No registration✓ No credit card✓ No hidden fees✓ Start practicing immediately
Not published Pass Rate
100+ Questions
100% Free
1 / 100
Question 1
Score: 0/0

Which STL sequence container provides constant-time random access AND amortized constant-time push_back, but only linear-time insertion in the middle?

A
B
C
D
to track
2026 Statistics

Key Facts: C++ CPP Exam

40

Exam Questions

C++ Institute CPP-22-02 syllabus

65 min

Exam Duration

C++ Institute CPP-22-02 syllabus

70%

Passing Score

C++ Institute CPP-22-02 syllabus

$295

Exam Fee (USD)

C++ Institute / Pearson VUE

Pearson VUE

Test Provider

OpenEDG C++ Institute

CPA

Recommended Prereq

C++ Institute prerequisites

C++ Certified Professional Programmer (CPP-22-02) is a 40-question, 65-minute proctored exam delivered by Pearson VUE. Passing score is 70% and the exam fee is approximately $295 USD. CPP tests advanced STL fluency: vector, deque, list, stack, queue, priority_queue, set, multiset, map, multimap; iterator categories; non-modifying algorithms (find, count, search); modifying algorithms (copy, transform, replace, remove, reverse, rotate, partition); sort, stable_sort, lower_bound, upper_bound, binary_search; merge and heap operations; min/max and set operations; functional utilities (function, bind, mem_fn, ref); advanced I/O manipulators; and function and class templates with full and partial specialization.

Sample C++ CPP Practice Questions

Try these sample questions to test your C++ CPP exam readiness. Each question includes a detailed explanation. Start the interactive quiz above for the full 100+ question experience with AI tutoring.

1Which STL sequence container provides constant-time random access AND amortized constant-time push_back, but only linear-time insertion in the middle?
A.std::vector
B.std::list
C.std::forward_list
D.std::set
Explanation: std::vector stores elements in a contiguous block, giving O(1) random access via operator[] and amortized O(1) push_back due to geometric reallocation. Insertion in the middle is O(n) because elements after the insertion point must shift. std::list gives O(1) middle insertion but no random access; std::set is associative, not sequential.
2Given std::vector<int> v = {1,2,3,4,5}; v.erase(v.begin() + 2); what does v contain afterwards?
A.{1, 2, 4, 5}
B.{1, 2, 3, 5}
C.{1, 2, 3, 4, 5}
D.{2, 3, 4, 5}
Explanation: v.begin() + 2 points at the element with value 3 (index 2). erase removes that element and shifts the tail left, so the vector becomes {1, 2, 4, 5}. erase returns an iterator to the new position of the element that followed the erased one (here, the 4).
3What is the iterator category of std::list<T>::iterator?
A.Forward iterator
B.Random-access iterator
C.Bidirectional iterator
D.Input iterator
Explanation: std::list is a doubly linked list, so its iterator can move forward and backward (++it and --it) but does not support random access (it + n in O(1) is not guaranteed). That makes it a bidirectional iterator. std::vector and std::deque iterators are random-access; std::forward_list iterators are only forward.
4Why does std::sort require its iterator range to be random-access?
A.It needs to call .size() on the underlying container
B.Internally it uses introsort, which needs constant-time arbitrary jumps for partitioning
C.Random-access iterators are the only ones that support operator==
D.Random-access iterators avoid copying elements during a swap
Explanation: std::sort is typically implemented as introsort (quicksort + heapsort + insertion sort), and its partitioning step needs to compute midpoints and compare iterators a constant distance apart. Those operations require random access. That is why std::list cannot be sorted with std::sort — you must use list::sort instead, which is a stable merge sort.
5What does this code print? #include <iostream> #include <vector> int main() { std::vector<int> v; v.reserve(10); std::cout << v.size() << ' ' << v.capacity(); }
A.10 10
B.0 10
C.10 0
D.0 0
Explanation: reserve increases capacity (the allocated buffer) without changing size (the number of constructed elements). After reserve(10) on an empty vector, size() is still 0 but capacity() is at least 10. Use resize, not reserve, if you actually want elements constructed.
6What is the time complexity of std::map<Key, Value>::find?
A.O(1)
B.O(log n)
C.O(n)
D.O(n log n)
Explanation: std::map is implemented as a balanced binary search tree (typically a red-black tree), so find walks log n levels to locate a key. std::unordered_map is the hash-based associative container that gives average O(1) lookup but worst-case O(n).
7Which function object should you pass as the third template argument of std::priority_queue<int> to turn it into a min-heap?
A.std::greater<int>
B.std::less<int>
C.std::not_equal_to<int>
D.std::minus<int>
Explanation: std::priority_queue defaults to std::less, which produces a max-heap (largest element on top). Passing std::greater<int> as the comparator inverts the ordering, producing a min-heap. The full type is std::priority_queue<int, std::vector<int>, std::greater<int>>.
8What does this code print? #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<int> v = {3, 1, 4, 1, 5, 9, 2, 6}; std::sort(v.begin(), v.end()); for (int x : v) std::cout << x; }
A.11234569
B.12345699
C.31415926
D.96543211
Explanation: std::sort sorts the vector in ascending order by default. The sorted sequence is 1,1,2,3,4,5,6,9 — printing without separators yields 11234569.
9What does the erase-remove idiom achieve?
A.Sorts the container while removing duplicates
B.Forces the compiler to skip iterator invalidation checks
C.Removes only the first matching element from a container
D.Logically removes matching elements with std::remove and then physically erases them from the container
Explanation: std::remove (and remove_if) shift non-matching elements to the front and return an iterator to the new logical end, but do NOT change container size — the tail still holds unspecified values. To truly shrink the container you must call container.erase(remove(...), container.end()). This is the erase-remove idiom.
10What does this code print? #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<int> v = {1, 2, 3, 2, 4, 2, 5}; auto it = std::remove(v.begin(), v.end(), 2); std::cout << v.size() << ' ' << (it - v.begin()); }
A.7 4
B.4 4
C.7 7
D.4 7
Explanation: std::remove does NOT shrink the container — v.size() remains 7. It returns an iterator to the new logical end, which is at offset 4 (the four non-2 elements 1, 3, 4, 5 are at indices 0..3). The tail v[4]..v[6] now holds unspecified values.

About the C++ CPP Exam

The C++ Institute CPP exam (CPP-22-02) validates advanced C++ skills: STL sequence and associative containers, iterators, non-modifying and modifying algorithms, sorting and binary search, merge and heap operations, function objects and binders, advanced I/O with stream manipulators, and function and class templates with specialization.

Questions

40 scored questions

Time Limit

65 minutes

Passing Score

70%

Exam Fee

$295 (C++ Institute / OpenEDG)

C++ CPP Exam Content Outline

20%

Sequence Containers and Container Adapters

vector, deque, list, forward_list, array, and the stack/queue/priority_queue adapters: invariants, iterator invalidation, complexity, and idiomatic use.

15%

Associative and Unordered Containers

set, multiset, map, multimap with comparators; unordered_set/unordered_map basics; insertion, lookup, and erase semantics.

15%

Non-Modifying and Modifying Algorithms

find, count, search, mismatch, equal; copy, transform, replace, remove (erase-remove idiom), reverse, rotate, partition, and unique.

15%

Sorting, Binary Search, Merge, and Heap

sort, stable_sort, partial_sort, nth_element; lower_bound, upper_bound, equal_range, binary_search; merge, inplace_merge, set operations; make_heap, push_heap, pop_heap, sort_heap.

15%

Function Objects, Binders, and Lambdas

Standard function objects, std::function, std::bind, std::mem_fn, std::ref, and lambda expressions used as predicates and unary/binary functors.

10%

Advanced I/O Streams

Stream state, manipulators (setw, setfill, setprecision, fixed, scientific, hex, boolalpha, showbase, showpos), stream iterators, and string streams.

10%

Function and Class Templates

Template syntax, instantiation, full and partial specialization, default template parameters, non-type template parameters, and template-dependent name lookup.

How to Pass the C++ CPP Exam

What You Need to Know

  • Passing score: 70%
  • Exam length: 40 questions
  • Time limit: 65 minutes
  • Exam fee: $295

Keys to Passing

  • Complete 500+ practice questions
  • Score 80%+ consistently before scheduling
  • Focus on highest-weighted sections
  • Use our AI tutor for tough concepts

C++ CPP Study Tips from Top Performers

1Memorize iterator categories (input, output, forward, bidirectional, random-access) and which containers and algorithms require each — std::sort needs random-access, std::list cannot use it.
2Drill the erase-remove idiom: std::remove only shifts elements and returns a new logical end; container.erase(remove(...), end()) is what actually shrinks size.
3Know that std::map and std::set use strict weak ordering, not equality — a custom comparator that returns true for equal keys breaks the invariant.
4Learn the difference between sort (random-access only, not stable), stable_sort (stable, extra memory), partial_sort, and nth_element (partition by rank).
5Be fluent with lower_bound, upper_bound, equal_range, and binary_search — they require the range to already be sorted by the same comparator.
6Practice writing function and class templates with full and partial specialization, including non-type template parameters like template<int N>.
7Review I/O manipulators (setw, setfill, setprecision, fixed, scientific, hex, boolalpha, showpos) and remember setw applies only to the next insertion while setfill is sticky.
8Walk through priority_queue defaults — it is a max-heap by default (uses std::less); pass std::greater<T> as the third template parameter for a min-heap.

Frequently Asked Questions

What is on the C++ Institute CPP exam?

CPP-22-02 tests advanced C++ Standard Library skills. Major topics include STL sequence containers (vector, deque, list, forward_list, array), container adapters (stack, queue, priority_queue), associative containers (set, multiset, map, multimap), non-modifying algorithms (find, count, search), modifying algorithms (copy, transform, replace, remove, reverse, rotate, partition), sorting and binary search (sort, stable_sort, lower_bound, upper_bound, binary_search), merge and heap operations, set operations, function objects and binders, advanced stream I/O with manipulators, and function and class templates with full and partial specialization.

How long is the CPP exam and how many questions does it have?

The CPP-22-02 exam contains 40 questions delivered in 65 minutes, with about 10 additional minutes for the non-disclosure agreement and tutorial. Items are single-choice and multiple-choice questions, and many present a short C++ code listing and ask what the program prints.

What is the passing score for CPP?

The CPP-22-02 passing score is 70%. You need to answer at least 28 of the 40 items correctly. Because there is no published difficulty curve, treat 80% on practice tests as your safety margin before scheduling the live exam.

How much does the CPP exam cost?

The current C++ Institute CPP-22-02 exam fee is approximately USD 295 for a single attempt, with bundle pricing around USD 375 that includes one paid retake. Pricing is set by C++ Institute and OpenEDG and can vary by region or promotional voucher.

What are the prerequisites for CPP?

There are no formal prerequisites to register for CPP-22-02, but C++ Institute strongly recommends holding the CPA (C++ Certified Associate Programmer) credential first. CPA covers core language fundamentals; CPP assumes you already know inheritance, polymorphism, exceptions, operator overloading, and pointers, and focuses on the Standard Template Library and templates.

Who should take the C++ CPP certification?

CPP is built for working C++ developers who want a vendor-neutral validation of advanced Standard Library skills. Strong candidates write modern C++ daily, are fluent in STL container choice and iterator categories, can read template code that uses specialization, and routinely use algorithms, lambdas, and stream manipulators rather than reinventing them.