Introduction to Programming & C++ Basics

What You’ll Learn

By the end of this post, you’ll be able to:

  • Understand what programming is and why it matters
  • Know what C++ is and where it’s used
  • Set up your development environment
  • Write, compile, and run your first C++ program
  • Understand basic C++ syntax: comments, variables, and console output

What is Programming?

Programming is the process of writing instructions that a computer can execute. These instructions are written in a programming language. Think of it as telling the computer exactly what to do, step by step.

Programming allows us to:

  • Build applications, games, and websites
  • Automate repetitive tasks
  • Control hardware like robots
  • Solve real-world problems with logic and precision

Why Learn C++?

C++ is a general-purpose programming language known for its speed and power. It is widely used in:

  • Game development (e.g., Unreal Engine)
  • Operating systems and compilers
  • Embedded systems and hardware control
  • High-performance applications
  • Competitive programming and coding interviews

C++ is also a great language to learn the fundamentals of programming such as variables, loops, conditionals, functions, memory, and object-oriented programming.


Setting Up Your Environment

To start writing and running C++ programs, you need two things:

  1. Text Editor or IDE
    Examples: Visual Studio Code, Code::Blocks, CLion, or even a simple Notepad++
  2. C++ Compiler
    Examples: GCC (Linux), MinGW (Windows), Clang (macOS)

If you’re a beginner, the easiest way is to use an IDE like Code::Blocks or Visual Studio Code with the C++ extension.

Alternatively, you can use online compilers like:


Your First C++ Program: Hello, World!

Let’s write the most basic program in C++.

#include <iostream>

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

Explanation:

  • #include <iostream> tells the compiler to include the standard input/output stream library.
  • int main() is the starting point of every C++ program.
  • std::cout is used to print output to the screen.
  • std::endl ends the line (like pressing Enter).
  • return 0; ends the program and signals that it ran successfully.

Compiling and Running

If you’re using an IDE, just click “Run”.

If you’re using a terminal (e.g., with g++):

g++ hello.cpp -o hello
./hello

This compiles hello.cpp into an executable file named hello, then runs it.


C++ Basics: Line-by-Line

1. Comments

Use comments to explain your code.

// This is a single-line comment

/*
This is a multi-line comment.
It spans multiple lines.
*/

2. Variables

Variables store data. Each variable must have a type.

int age = 20;
double weight = 65.5;
char grade = 'A';
bool passed = true;

3. Printing Variables

#include <iostream>

int main() {
int age = 20;
std::cout << "Age: " << age << std::endl;
return 0;
}

Output:

Age: 20

The << operator is used to stream multiple things to cout.


Exercise: Write Your Own Program

Try writing a program that prints the following:

Welcome to Painless Programming!
C++ is powerful.

Hint: Use std::cout two times, or use \n to insert a new line.

Quiz Your Self!

Quiz: C++ Basics

Question 1/5

Summary

In this lesson, you learned:

  • What programming is
  • Why C++ is still a relevant and powerful language
  • How to set up your environment
  • How to write, compile, and run your first program
  • Some basic C++ concepts: comments, variables, and output

Coming Up Next

In the next post, we’ll explore data types, variables, and expressions in more depth — including strings, input handling, and how computers store numbers.

Scroll to Top