Variables in C++

ยท

1 min read

Hello and welcome back today I will be discussing how to declare variables and what variables are in C++.

Variables are essentially containers in which we can store values. Now why do we have to store values you ask ๐Ÿค”.

We store values in variables to use them for later. E.g.

int num1 = 5;
int num2 = 10;
cout<<num1+num2;

As you can see in the above example, we can store values in variables and then we can use that said variable for calculations, manipulations, counters and so on. However, there are some ruling conventions of variables in C++.

  1. All variable names must be unique

  2. When naming a variable it should be known what values are going to be stored in that variable

  3. Variable names can contain letters, numbers and underscores(_)

  4. Variable names must begin with letters or underscores(_)

  5. Variable names are case-sensitive so num and Num are two different variables

  6. There are certain reserve words in C++ like string or int so variables can't have those names

  7. There should be no spaces or special characters in your variable names

When declaring a variable you need to first type what datatype will it be. As discussed in my previous post.

That's it for variables in C++.

Here is the video corresponding video -

ย