First program in C++: the basics to get started

Getting started with programming can seem intimidating, especially when choosing a language like C++. Yet this language is an excellent starting point for understanding the foundations of object-oriented programming and computer logic in general. Known for its power and flexibility, C++ is widely used in software engineering, video games, finance, and embedded systems. Writing your first C++ program is an important step that lays solid foundations.

To understand how a C++ program works, it helps to have an overview of its structure. Every program begins with one or more preprocessor directives, followed by a main function called main(), and possibly contains other functions. C++ allows you to manipulate variables, control execution flow with conditions or loops, and interact with the user through display and input.

Let’s take a very simple example of a C++ program that displays a message to the user:

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
    return 0;
}

In this code, #include <iostream> indicates that we are using a library to handle input and output. The main() function is the entry point of the program. std::cout displays text on screen, and std::endl adds a line break. The return 0 instruction signals that the program ended successfully.

A good way to progress is to add interactivity. Here is an extended version that asks the user for their name:

#include <iostream>
#include <string>

int main() {
    std::string name;
    std::cout << "What is your name? ";
    std::getline(std::cin, name);
    std::cout << "Hello, " << name << " ! Nice to meet you." << std::endl;
    return 0;
}

Here, the line #include <string> allows manipulation of character strings. The std::getline() function reads a complete line entered by the user, which handles compound names. The use of std::cout remains central for displaying results.

C++ also shines through its ability to handle conditional structures. We can add a simple condition to check whether the user has entered a name or not:

if (name.empty()) {
    std::cout << "You haven't entered a name." << std::endl;
} else {
    std::cout << "Welcome, " << name << " !" << std::endl;
}

This approach makes the program more robust and better adapted to different situations. Learning C++ involves these small adjustments that help better understand conditional logic and program behavior.

Variables are at the heart of every C++ program. You can declare variables of different types: integers (int), decimals (float, double), characters (char), booleans (bool), and strings (std::string). Here is an example of variable manipulation with an arithmetic operation:

#include <iostream>

int main() {
    int a = 5;
    int b = 3;
    int result = a + b;
    std::cout << "The result of " << a << " + " << b << " is: " << result << std::endl;
    return 0;
}

This type of program shows how to store values, perform calculations, and display results. It is also an excellent exercise for understanding how C++ handles different data types.

Once you understand the fundamentals, it becomes possible to create more useful programs. For example, a small command-line calculator or a temperature converter. This allows you to practice while producing code that has concrete meaning.

C++ is a rigorous but rewarding language. It requires thinking about memory management, data typing, and code structure, which builds excellent reflexes for any programmer. To progress, it is important to practice regularly, read documentation, explore errors, and learn to fix them.

With these first foundations, anyone can create a simple but complete C++ program. Experience comes through experimentation. The pleasure of seeing your own code execute correctly is an incomparable source of motivation to go further. Whether for the joy of learning, for studies, or to prepare a career in software development, C++ remains a timeless choice.

Don’t forget that C++ is also the language behind many iconic video games, high-performance applications, and professional tools. Mastering it opens doors to many areas of the tech industry.

Sudoku Quest

Follow us on YouTube and Instagram


There you go, now you can shine at parties…

Itamde courses

Recent Posts

Recent Comments

Itamde is also an online programming school.

Itamde

Learn what you want, at your own pace

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You may also be interested in…

Artificial intelligence is reshaping every pixel

Artificial intelligence is reshaping every pixel

Just a few years ago, editing a photo meant spending hours working meticulously in Photoshop, mastering layers, masks and curves. In 2026, everything has shifted. AI photo editing tools no longer settle for automatic filters — they understand image content, anticipate...

The 10 Best Free AI Tools for Developers in 2026

The 10 Best Free AI Tools for Developers in 2026

Artificial intelligence is transforming how developers write, test, and deploy code. In 2026, many AI tools are freely accessible, offering capabilities that would have seemed impossible just a few years ago. Whether you're a beginner or experienced developer, these...

CSS colors

CSS colors

CSS colors can be defined in hexadecimal. Hexadecimal uses three components: red, green, and blue. You can define colors in shorthand hexadecimal: for example #DC2 corresponds to #DDCC22. Note that some colors cannot be abbreviated. The goal is to shorten your...

Stay up to date with the latest news and developments

Access restricted content

Discover behind-the-scenes details of our projects, exclusive resources, and the progress of our creations in real time.

Sign up for our newsletter

Receive our news, creative insights, and updates from the studio directly in your inbox.

Follow us

Join our community on social media to follow our daily projects and interact with us.