GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++
  • Hello World
  • Display Your Name
  • User Input
  • Sum of Two Numbers

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — C++ Programming Examples - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++

C++ Programming Examples

Last Updated : 31 Jul, 2026

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:

  • Hello World
  • Display Your Name
  • User Input
  • Sum of Two Numbers
  • Swap two numbers
  • Size of int, float, double, char
  • Float Multiplication
  • ASCII Value of a Character 
  • Convert Fahrenheit to Celsius
  • Calculate Simple Interest
  • Calculate Compound Interest
  • 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.

  • Check for Even Odd
  • Largest Among 3
  • Vowel/Consonant Check
  • Leap Year Check
  • Multiplication Table
  • Sum of n Natural Numbers
  • Factorial of a Number
  • Reverse a Number
  • GCD of two numbers
  • LCM of two numbers
  • Palindrome Check
  • Prime Check
  • Primes in Range
  • Neon Numbers in Range
  • Armstrong Number
  • Armstrong Numbers Between 1 to 1000
  • nth Fibonacci Number
  • Even Index Fibonacci Sum
  • Calculate the Power of a Number
  • Factors of a Natural Number
  • 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.

  • Right Half Pyramid
  • Left Half Pyramid
  • Full Pyramid
  • Inverted Pyramid
  • Triangle Pattern
  • Number Pattern
  • Character Pattern
  • Continuous Character Pattern
  • Diamond Pyramid
  • Inverted Hollow Pyramid 
  • Hollow Diamond Pyramid
  • Pascal's Triangle
  • Floyd's Triangle
  • 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.

  • Primes in Range
  • Sum of Two Primes Check
  • Recursive Sum of n
  • Factorial using Recursion
  • Recursive Sentence Reverse
  • Power using Recursion
  • 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.

  • Array Equality Check
  • Array Max & Min
  • Array Average
  • Merge Arrays
  • 2D Array
  • Common Array Elements
  • Remove Duplicates
  • Remove Element
  • Prefix Sum
  • Rotate Array
  • 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.

  • Matrix Addition
  • Matrix Equality Check
  • Matrix Diagonal Check
  • Matrix Boundary Elements
  • Matrix Transpose
  • Matrix Determinant
  • Normal and Trace of Matrix
  • Matrix Multiplication
  • Rotate Matrix
  • Swap First & Last Rows
  • Matrix Prefix Sum

C++ Pointers Programs

With arrays and matrices understood, explore memory management with pointers, learning dynamic allocation and manipulation of memory.

  • Pointers
  • Array of Pointers
  • Void Pointer
  • Reference To a Pointer
  • Function pointer
  • this Pointer
  • Opaque Pointer

C++ String Programs

Problems in this section focus on string manipulation, including operations like concatenation, comparison, reversal, and finding substrings.

  • String Length
  • Access Characters
  • Unicode at index
  • Replace a Character
  • String Compare
  • Concatenate Strings
  • Add Binary Strings
  • Remove Leading Zeros
  • Lexicographical Compare
  • Reverse String
  • Palindrome Check
  • First Letters of Words
  • Insert String
  • Split String
  • Stack based Reverse
  • 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.

  • Binary to Decimal
  • Binary to Octal
  • Octal to Decimal
  • Decimal to Octal
  • Hexadecimal to Decimal
  • Decimal to Hexadecimal
  • Decimal to Binary
  • Boolean to String
  • String to Double
  • Double to String
  • String to Long
  • Long to String
  • Int to Char
  • 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.

  • Structure Function
  • Student Structure
  • 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.

  • Create a Class and Object
  • Encapsulation
  • Inheritance
  • Abstraction in Class
  • Data Hiding in Class
  • Polymorphism in Class
  • Function Overloading
  • Function Overriding
  • Usage of Access Modifier
  • Use of This Keyword in Class
  • Usage of Static keyword
  • Friend Functions
  • Virtual Destructor
  • Abstract Class
  • Singleton Class
  • Interface
  • Overload Increment ++ and Decrement
  • 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.

  • Reverse Vector
  • Copy Vector
  • Compare Vectors
  • Convert a Vector of Pairs to a Map
  • Show transform ()
  • Merge Maps
  • Stack Of Pairs
  • Multiset Frequency
  • Multiset with Custom Comparator
  • String Permutation
  • Array Permutation
  • Max & Min in Set
  • Next Greater Element
  • Reverse Priority
  • Binary Search Using STL

C++ Searching and Sorting Programs

In this section, we implement algorithms for searching and sorting data, optimizing performance and efficiency.

  • Linear Search
  • Binary Search
  • String Sort
  • Sort 2D Array Rows
  • Sort Descending
  • Sort Ascending
  • Sort 0-1-2 Array
  • Wave Sort
  • Partial Sort
  • 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.

  • New File
  • Temporary File
  • Write File
  • Rename File
  • Read-Only File
  • Compare File Paths
  • Copy File
  • Append File
  • List Files
  • Append String
  • 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.

  • Runtime Exceptions
  • Error Types
  • Exception Methods
  • Checked Exceptions
  • Handle Unchecked Exceptions
  • Divide by Zero and Multiple Exceptions
  • Unreachable Code Error
  • Thread and Memory Errors

C++ Date and Time Programs

In this section, we see how to handle data and times in our programs.

  • Calendar Dates
  • Current Date and Time
  • Local Time to GMT

C++ Miscellaneous Programs

  • Quotient & Remainder
  • sizeof() Operator
  • Name Initials
  • Power Without Using * and / Operators
  • Quadratic Roots
  • Random Doubles
  • Hide and Show a Console Window
  • Run a C++ Program Without Namespace
  • Custom Map (Header)
  • Zero XOR Triplets.
Comment

Explore

    C++ Basics
    • Introduction2 min read
    • Data Types4 min read
    • Variables4 min read
    • Operators9 min read
    • Basic Input / Output2 min read
    • Control Flow Statements15+ min read
    • Loops7 min read
    • Functions5 min read
    • Arrays5 min read
    Core Concepts
    • Pointers and References4 min read
    • new and delete Operators5 min read
    • Templates in C++7 min read
    • Struct Union Enum3 min read
    • Exception Handling5 min read
    • File Handling9 min read
    • Multithreading6 min read
    • Namespace5 min read
    OOP
    • OOP Concepts10 min read
    • Inheritance6 min read
    • Polymorphism5 min read
    • Encapsulation3 min read
    • Abstraction4 min read
    Standard Template Library(STL)
    • STL3 min read
    • Container Library3 min read
    • Iterators10 min read
    • Algorithm Library3 min read
    Practice & Problems
    • Interview Questions15+ min read
    • Programming Examples4 min read
    Courses
    • Placement 360 Course2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.