Courses
Search... Tutorials Sign In
Interview Prep
C++ Tutorial Interview Questions Examples Quizzes Projects Cheatsheet OOP Exception Handling STL DSA C++
C++ Programming Examples
Last Updated : 20 Sep, 2025
Writing C++ programs yourself is the best way to learn the C++ language. C++ programs are also
asked in the interviews. This article covers the top practice problems for basic C++ programs on topics
like control flow, patterns, and functions to complex ones like pointers, arrays, and strings.
Basic C++ Programs
Start with foundational tasks such as printing statements, taking input, and performing basic
arithmetic operations:
1. Hello World
2. Display Your Name
3. User Input
4. Sum of Two Numbers
5. Swap two numbers
6. Size of int, float, double, char
7. Float Multiplication
8. ASCII Value of a Character
9. Convert Fahrenheit to Celsius
10. Calculate Simple Interest
11. Calculate Compound Interest
12. Area and Perimeter of Rectangle
C++ Control Flow Programs
After basic operations, this section introduces decision-making structures and looping techniques that
allow you to control the flow of your program.
1. Check for Even Odd
2. Largest Among 3
3. Vowel/Consonant Check
4. Leap Year Check
5. Multiplication Table
6. Sum of n Natural Numbers
7. Factorial of a Number
8. Reverse a Number
9. GCD of two numbers
10. LCM of two numbers
11. Palindrome Check
12. Prime Check
13. Primes in Range
14. Neon Numbers in Range
15. Armstrong Number
16. Armstrong Numbers Between 1 to 1000
17. nth Fibonacci Number
18. Even Index Fibonacci Sum
19. Calculate the Power of a Number
20. Factors of a Natural Number
21. Basic Calculator
C++ Pattern Printing Programs
Once you're familiar with loops, it's time to apply them by solving problems that involve printing
various patterns and shapes.
1. Right Half Pyramid
2. Left Half Pyramid
3. Full Pyramid
4. Inverted Pyramid
5. Triangle Pattern
6. Number Pattern
7. Character Pattern
8. Continuous Character Pattern
9. Diamond Pyramid
10. Inverted Hollow Pyramid
11. Hollow Diamond Pyramid
12. Pascal's Triangle
13. Floyd's Triangle
14. Reverse Floyd's Triangle
C++ Function Programs
Now that you’re comfortable with patterns, move on to writing functions, exploring overloading,
recursion, and how functions improve code reusability.
1. Primes in Range
2. Sum of Two Primes Check
3. Recursive Sum of n
4. Factorial using Recursion
5. Recursive Sentence Reverse
6. Power using Recursion
7. Variadic Templates
C++ Array Programs
This section focuses on problems related to arrays, including initialization, traversal, manipulation, and
operations like summing elements or finding the largest/smallest element.
1. Array Equality Check
2. Array Max & Min
3. Array Average
4. Merge Arrays
5. 2D Array
6. Common Array Elements
7. Remove Duplicates
8. Remove Element
9. Prefix Sum
10. Rotate Array
11. Reverse Copy Array
C++ Matrix Programs
After arrays, extend your skills to 2D matrices, learning how to handle more complex data structures
and perform matrix operations.
1. Matrix Addition
2. Matrix Equality Check
3. Matrix Diagonal Check
4. Matrix Boundary Elements
5. Matrix Transpose
6. Matrix Determinant
7. Normal and Trace of Matrix
8. Matrix Multiplication
9. Rotate Matrix
10. Swap First & Last Rows
11. Matrix Prefix Sum
C++ Pointers Programs
With arrays and matrices understood, explore memory management with pointers, learning dynamic
allocation and manipulation of memory.
1. Pointers
2. Array of Pointers
3. Void Pointer
4. Reference To a Pointer
5. Function pointer
6. this Pointer
7. Opaque Pointer
C++ String Programs
Problems in this section focus on string manipulation, including operations like concatenation,
comparison, reversal, and finding substrings.
1. String Length
2. Access Characters
3. Unicode at index
4. Replace a Character
5. String Compare
6. Concatenate Strings
7. Add Binary Strings
8. Remove Leading Zeros
9. Lexicographical Compare
10. Reverse String
11. Palindrome Check
12. First Letters of Words
13. Insert String
14. Split String
15. Stack based Reverse
16. Pangram Check
C++ Conversion Programs
In this section we tackle data conversion problems, like changing between different types and
formats, to better handle user input and outputs.
1. Binary to Decimal
2. Binary to Octal
3. Octal to Decimal
4. Decimal to Octal
5. Hexadecimal to Decimal
6. Decimal to Hexadecimal
7. Decimal to Binary
8. Boolean to String
9. String to Double
10. Double to String
11. String to Long
12. Long to String
13. Int to Char
14. Char to Int
C++ Structures Programs
Now that you know how to handle basic data types, explore structures to group related data together
and manage complex data more effectively.
1. Structure Function
2. Student Structure
3. Structure Sorting
C++ Class and Object Programs
With structures covered, learn object-oriented programming by creating classes and objects, which
allow you to model real-world entities.
1. Create a Class and Object
2. Encapsulation
3. Inheritance
4. Abstraction in Class
5. Data Hiding in Class
6. Polymorphism in Class
7. Function Overloading
8. Function Overriding
9. Usage of Access Modifier
10. Use of This Keyword in Class
11. Usage of Static keyword
12. Friend Functions
13. Virtual Destructor
14. Abstract Class
15. Singleton Class
16. Interface
17. Overload Increment ++ and Decrement
18. Add Two Complex Numbers
C++ STL Programs
Explore the Standard Template Library (STL) to use pre-built data structures and algorithms that
simplify your code and improve performance.
1. Reverse Vector
2. Copy Vector
3. Compare Vectors
4. Convert a Vector of Pairs to a Map
5. Show transform ()
6. Merge Maps
7. Stack Of Pairs
8. Multiset Frequency
9. Multiset with Custom Comparator
10. String Permutation
11. Array Permutation
12. Max & Min in Set
13. Next Greater Element
14. Reverse Priority
15. Binary Search Using STL
C++ Searching and Sorting Programs
In this section, we implement algorithms for searching and sorting data, optimizing performance and
efficiency.
1. Linear Search
2. Binary Search
3. String Sort
4. Sort 2D Array Rows
5. Sort Descending
6. Sort Ascending
7. Sort 0-1-2 Array
8. Wave Sort
9. Partial Sort
10. Search in Rotated array
C++ File Handling Programs
After mastering classes and objects, dive into file handling, enabling your programs to read from and
write to external files for persistent storage.
1. New File
2. Temporary File
3. Write File
4. Rename File
5. Read-Only File
6. Compare File Paths
7. Copy File
8. Append File
9. List Files
10. Append String
11. Read and Write File
C++ Exception Handling Programs
As your programs become more complex, learn to handle errors gracefully with exception handling,
ensuring your code can manage unexpected conditions.
1. Runtime Exceptions
2. Error Types
3. Exception Methods
4. Checked Exceptions
5. Handle Unchecked Exceptions
6. Divide by Zero and Multiple Exceptions
7. Unreachable Code Error
8. Thread and Memory Errors
C++ Date and Time Programs
In this section, we see how to handle data and times in our programs.
1. Calendar Dates
2. Current Date and Time
3. Local Time to GMT
C++ Miscellaneous Programs
1. Quotient & Remainder
2. sizeof() Operator
3. Name Initials
4. Power Without Using * and / Operators
5. Quadratic Roots
6. Random Doubles
7. Hide and Show a Console Window
8. Run a C++ Program Without Namespace
9. Custom Map (Header)
10. Zero XOR Triplets.
Comment A abhish… 73
Article Tags: C++
Explore
C++ Basics
Core Concepts
OOP in C++
Standard Template Library(STL)
Practice & Problems
Company Explore Tutorials Courses Videos Preparation
About Us POTD Programming ML and Data DSA Corner
Corporate & Communications Address: Legal Job-A- Languages Science Python Interview
Privacy Thon DSA DSA and Java Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Blogs Web Placements C++ Aptitude
Pradesh (201305) Contact Us Nation Technology Web Web Puzzles
Advertise Skill Up AI, ML & Development Development GfG 160
Registered Address:
with us Data Science Programming Data Science System Design
K 061, Tower K, Gulshan Vivante GFG DevOps Languages CS Subjects
Apartment, Sector 137, Noida, Gautam
Corporate CS Core DevOps &
Buddh Nagar, Uttar Pradesh, 201305
Solution Subjects Cloud
Campus Interview GATE
Training Preparation Trending
Program Software and Technologies
Tools
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved