C++ Programming Exercises

Sharpen your C++ skills with comprehensive topic-wise practice problems

Beginner to Advanced 200+ Problems Topic-wise Lists

Practice Makes Perfect

Master C++ programming through hands-on practice with our comprehensive collection of exercises. Each topic includes problems of varying difficulty levels to help you strengthen your understanding and problem-solving skills.

200+ Problems

Comprehensive coverage of all C++ topics

Progressive Difficulty

From beginner to advanced levels

Practical Focus

Real-world problem scenarios

1. Introduction to C++, Basic Syntax and Structure

Get familiar with C++ program structure and basic syntax

  1. Write a program that displays "Hello, World!" on the screen. Easy
  2. Create a program that includes necessary headers, main function, and returns 0. Easy
  3. Write a program with single-line and multi-line comments explaining the code. Easy
  4. Create a program that uses the std namespace and demonstrates its purpose. Easy
  5. Write a program that demonstrates the difference between C and C++ compilation. Medium
  6. Create a program that shows the basic structure of a C++ program with multiple functions. Medium
  7. Write a program that demonstrates the use of preprocessor directives. Medium
  8. Create a program that uses both C-style and C++ style input/output. Medium
  9. Write a program that demonstrates namespace pollution and how to avoid it. Hard
  10. Create a program that shows the memory layout of a C++ program. Hard

2. Variables and Data Types, Constants and Literals

Practice working with different data types and constants

  1. Declare variables of different data types (int, float, double, char, bool) and display their values. Easy
  2. Create a program that uses const and #define to declare constants and demonstrate their usage. Easy
  3. Write a program that demonstrates implicit and explicit type conversion in C++. Medium
  4. Create a program that displays the size of various data types using the sizeof operator. Easy
  5. Write a program that demonstrates the use of literals (integer, floating-point, character, string). Medium
  6. Create a program that shows the range and precision of different data types. Medium
  7. Write a program that demonstrates variable scope and lifetime. Medium
  8. Create a program that uses enumerations and shows their advantages over constants. Medium
  9. Write a program that demonstrates the use of the auto keyword for type inference. Hard
  10. Create a program that shows the difference between lvalues and rvalues. Hard

3. Input and Output (I/O), Operators

Practice using I/O streams and different operators

  1. Write a program that takes user input and displays it with appropriate formatting. Easy
  2. Create a calculator program that performs basic arithmetic operations on two numbers. Easy
  3. Write a program that demonstrates the use of relational and logical operators. Easy
  4. Create a program that demonstrates the use of compound assignment operators. Easy
  5. Write a program that uses bitwise operators to manipulate data. Medium
  6. Create a program that demonstrates operator precedence and associativity. Medium
  7. Write a program that uses stream manipulators to format output. Medium
  8. Create a program that handles input validation and error checking. Medium
  9. Write a program that demonstrates the use of the conditional (ternary) operator. Hard
  10. Create a program that uses the comma operator and demonstrates its proper use cases. Hard

4. Conditional Control Statements

Practice using if, else if, else, and switch statements

  1. Write a program that checks if a number is positive using an if statement. Easy
  2. Create a program that determines the grade based on marks using if-else if-else statements. Medium
  3. Write a program that implements a simple calculator using switch case statements. Medium
  4. Create a program that uses nested if statements to solve a complex conditional problem. Hard
  5. Write a program that demonstrates the difference between if-else and switch statements. Medium
  6. Create a program that uses conditional statements to determine leap years. Medium
  7. Write a program that implements a menu-driven interface using switch cases. Medium
  8. Create a program that uses conditional operators to find the maximum of three numbers. Medium
  9. Write a program that demonstrates fall-through behavior in switch statements and how to avoid it. Hard
  10. Create a program that uses conditional statements to solve a quadratic equation. Hard

5. Loops

Practice using for, while, and do-while loops

  1. Write a program that prints numbers from 1 to 10 using a for loop. Easy
  2. Create a program that calculates the sum of numbers until the user enters 0 using a while loop. Medium
  3. Write a program that demonstrates the difference between while and do-while loops. Medium
  4. Create a program that prints patterns using nested loops (e.g., pyramid, diamond). Hard
  5. Write a program that uses loops to calculate the factorial of a number. Medium
  6. Create a program that finds prime numbers within a range using loops. Medium
  7. Write a program that demonstrates the use of break and continue statements in loops. Medium
  8. Create a program that implements the Fibonacci sequence using loops. Medium
  9. Write a program that uses loops to reverse a number. Hard
  10. Create a program that demonstrates infinite loops and how to avoid them. Hard

6. Arrays

Practice working with single and multi-dimensional arrays

  1. Write a program that declares, initializes, and displays the elements of an array. Easy
  2. Create a program that finds the sum, average, maximum, and minimum of array elements. Medium
  3. Write a program that performs matrix addition and multiplication using 2D arrays. Hard
  4. Implement sorting algorithms (bubble sort, selection sort) to sort an array of numbers. Hard
  5. Create a program that searches for an element in an array using linear and binary search. Medium
  6. Write a program that demonstrates array traversal using pointers. Medium
  7. Create a program that finds the second largest element in an array. Medium
  8. Write a program that merges two sorted arrays into a third sorted array. Hard
  9. Create a program that finds the frequency of elements in an array. Medium
  10. Write a program that implements a simple stack using arrays. Hard

7. Strings

Practice working with C-style strings and C++ string class

  1. Write a program that demonstrates declaration, initialization, and display of C++ strings. Easy
  2. Create a program that performs various string operations (concatenation, comparison, length). Medium
  3. Write a program that reverses a string, converts case, and finds substrings. Medium
  4. Create a program that checks if a given string is a palindrome. Medium
  5. Write a program that counts vowels, consonants, digits, and special characters in a string. Medium
  6. Create a program that demonstrates the difference between C-style strings and C++ strings. Medium
  7. Write a program that tokenizes a string using delimiters. Hard
  8. Create a program that removes all occurrences of a character from a string. Medium
  9. Write a program that checks if two strings are anagrams of each other. Hard
  10. Create a program that implements basic string encryption and decryption. Hard

8. Functions, Recursion

Practice creating functions and using recursion

  1. Write a program with functions that perform basic mathematical operations. Easy
  2. Create a program that demonstrates function overloading with different parameter types. Medium
  3. Write a program that calculates factorial and Fibonacci numbers using recursion. Medium
  4. Create a program that demonstrates the use of default arguments in functions. Medium
  5. Write a program that uses pass by value, pass by reference, and pass by pointer. Medium
  6. Create a program that demonstrates inline functions and their benefits. Medium
  7. Write a program that uses recursive functions to solve the Tower of Hanoi problem. Hard
  8. Create a program that demonstrates function templates for generic programming. Hard
  9. Write a program that uses recursive functions to implement binary search. Hard
  10. Create a program that demonstrates the use of static variables in functions. Medium

9. Pointers, Dynamic Memory

Practice working with pointers and dynamic memory allocation

  1. Write a program that demonstrates declaration, initialization, and dereferencing of pointers. Medium
  2. Create a program that demonstrates pointer arithmetic with arrays. Medium
  3. Write a program that uses new and delete operators for dynamic memory allocation. Hard
  4. Create a program that creates and manipulates dynamic arrays using pointers. Hard
  5. Write a program that demonstrates the relationship between arrays and pointers. Medium
  6. Create a program that uses pointers to swap values of variables. Medium
  7. Write a program that demonstrates the use of pointers to functions. Hard
  8. Create a program that implements a linked list using dynamic memory allocation. Hard
  9. Write a program that demonstrates memory leaks and how to avoid them. Hard
  10. Create a program that uses pointers to create and manipulate 2D arrays dynamically. Hard

10. OOPS

Practice Object-Oriented Programming concepts

  1. Create a class to represent a Rectangle with methods to calculate area and perimeter. Medium
  2. Write a program that demonstrates different types of constructors and destructors. Medium
  3. Create a program that demonstrates different types of inheritance (single, multiple, multilevel). Hard
  4. Write a program that demonstrates compile-time and runtime polymorphism. Hard
  5. Create a program that demonstrates encapsulation with getter and setter methods. Medium
  6. Write a program that demonstrates friend functions and friend classes. Hard
  7. Create a program that demonstrates abstract classes and pure virtual functions. Hard
  8. Write a program that demonstrates operator overloading for a custom class. Hard
  9. Create a program that demonstrates the use of static members in a class. Medium
  10. Write a program that demonstrates composition and aggregation relationships between classes. Hard

11. STL

Practice using the Standard Template Library

  1. Write a program that demonstrates various operations on vectors (push, pop, iterate). Medium
  2. Create a program that demonstrates the use of list and deque containers. Medium
  3. Write a program that uses map and set to store and retrieve key-value pairs. Hard
  4. Create a program that uses STL algorithms (sort, find, count) on containers. Hard
  5. Write a program that demonstrates the use of STL stack and queue containers. Medium
  6. Create a program that uses STL priority_queue to implement a min-heap and max-heap. Hard
  7. Write a program that demonstrates the use of STL iterators with different containers. Medium
  8. Create a program that uses STL algorithms to manipulate strings. Medium
  9. Write a program that demonstrates the use of STL functors and lambda expressions. Hard
  10. Create a program that uses STL to implement common data structures and algorithms. Hard

12. File handling

Practice reading from and writing to files

  1. Write a program that creates a file and writes data to it. Medium
  2. Create a program that reads data from a file and displays it on the screen. Medium
  3. Write a program that appends data to an existing file and modifies its content. Hard
  4. Create a program that reads and writes binary data to files. Hard
  5. Write a program that copies the contents of one file to another. Medium
  6. Create a program that counts characters, words, and lines in a text file. Medium
  7. Write a program that demonstrates random access in files. Hard
  8. Create a program that uses file handling to create a simple database system. Hard
  9. Write a program that demonstrates error handling in file operations. Medium
  10. Create a program that uses file handling to implement a simple text editor. Hard

13. Exception handling

Practice handling exceptions in C++

  1. Write a program that uses try-catch blocks to handle division by zero exception. Medium
  2. Create a program that uses multiple catch blocks to handle different types of exceptions. Medium
  3. Write a program that creates and throws custom exception classes. Hard
  4. Create a program that demonstrates exception propagation across function calls. Hard
  5. Write a program that demonstrates the use of the noexcept specifier. Hard
  6. Create a program that uses RAII (Resource Acquisition Is Initialization) for exception safety. Hard
  7. Write a program that demonstrates stack unwinding during exception handling. Hard
  8. Create a program that uses exception handling in file operations. Medium
  9. Write a program that demonstrates the use of standard exception classes. Medium
  10. Create a program that implements a robust error handling system using exceptions. Hard

14. Modern C++

Practice modern C++ features (C++11 and beyond)

  1. Write a program that demonstrates the use of the auto keyword for type inference. Medium
  2. Create a program that uses lambda expressions with STL algorithms. Hard
  3. Write a program that uses unique_ptr, shared_ptr, and weak_ptr for memory management. Hard
  4. Create a program that demonstrates move semantics and rvalue references. Hard
  5. Write a program that uses range-based for loops for container traversal. Medium
  6. Create a program that demonstrates the use of constexpr for compile-time computations. Hard
  7. Write a program that uses variadic templates for functions with variable arguments. Hard
  8. Create a program that demonstrates the use of std::thread for multithreading. Hard
  9. Write a program that uses std::async for asynchronous operations. Hard
  10. Create a program that demonstrates new features from C++17 and C++20 standards. Hard

Ready to Practice?

Start with the basics and gradually move to advanced topics. Consistent practice is key to mastering C++ programming.

Download All Exercises

PDF version with all 140+ exercises