---
title: 1.5 Variables
description: A variable is a named storage location used to hold data during program execution. Every variable has a data type that determines the kind of value it can store. This example demonstrates how variables are declared, assigned values, and used…
url: "https://edcret.in/docs/cpp-programming/basic-refreshers-cplusplus/1-5-variables/"
updated: "2026-07-28"
category: C++ Programming / Basic Refreshers
---

# 1.5 Variables

A variable is a named storage location used to hold data during program execution. Every variable has a data type that determines the kind of value it can store.

This example demonstrates how variables are declared, assigned values, and used in expressions.

## Source Code

```
#include <iostream>

int main()
{
    int age;

    age = 21;

    std::cout << "Age: " << age << '\n';

    return 0;
}
```

## Output

```
Age: 21
```

## Explanation

- `int age;` declares a variable named `age` that can store integer values.
- Declaring a variable allocates storage for the specified data type.
- `age = 21;` assigns the value `21` to the variable using the assignment operator (`=`).
- The value stored in a variable can be modified by assigning a new value.
- `std::cout << "Age: " << age << '\n';` retrieves the value stored in `age` and writes it to the standard output stream.
- `return 0;` terminates the program successfully.
