Hello YouTube world, I'm Parvez and this is our second video in C++ programming language
In this video we are going to talk about variables, data types and also different rules for the
variables in C++ programming language. Now first of all, what are variables
Now in C++ variables are used to store data in a memory location, which we will use from
that variable during our program. So now let me just show you the example of variables that you can create
So if you are familiar with the programming language like Python, when you create a variable
you do need to specify the data type, but in C++ you need to specify the data type and
there are different data types that you can use, for example we have float, we have int
we have char or we can call it char. So now first let me just show you some example of this
For example I want to define int num and this int is an integer and I'm going to specify
the value to 10. Now I can, let me just cout this, so cout and let me just cout the num and line
Now if I press Ctrl F5 and you will see that I'm receiving 10 in here
Okay, now you can see that this is 10. Now also you can specify, let me just specify for example you can use float, so float a
to 10.5 and you can cout this, so let me just copy this and a, so like this
Now if I press Ctrl F5, now you can see I have 10.5 in here
Also you can, for example let me just do another one, so this is char or char, this is for
using character, so for example not a, let me just do it b, b and you can cout this
so let me just cout the b, sorry the b and if you run this Ctrl F5, now you can see the
value is b, we have received now. Also you can, so let me just show you there are some rules and some rules for the defining variables
So the first rule is that for example variable names should be capital letter from a to z
or small letter from a to z. So in here you can see we have n, so if I make it capital letter and if I print this
so you can see there is no problem and we can print this, we can run this
And so this was the first rule, now the second rule is, so you can see that we have there
is no problem and we are not getting any error. Now the second rule is that when you want to declare a variable, so the first character
must be a letter or underscore, so we cannot use for example, this should be a letter or
you can use for example let me add underscore and you can print this, so there is no problem
in this. But if I change this to for example 8, so now we are not allowed to do this, to declare
the variable like this. And the third rule is that we cannot use blank space in the variable
So for example you cannot declare a variable like this, so you cannot add space between
the variables. And there are a lot of rules, so the first rule is that we can use characters like, we
cannot use characters like for example if you say dollar sign or hash for example let
me declare a variable like this, we cannot declare a variable like this
So now this was some rules for the variables, now let me just show you that how you can
do some mathematics, you can add numbers or you can multiply numbers, divide numbers
So let me just declare two variables int a, let me give it to 9 and also we have int b
this is for example sex, ok? Now the first one I am going to just declare another variable called int sum
So you can, first we are going to just sum these two numbers and you can see out, you
can add sum and add a line. So now if I run this, so now you can see the result is 15 because a plus 9 plus 6 it will
be 15. Now you can do for example if you want to minus you can do this, so if you press control
F5 for running, you will see that we are receiving 3. Also you can do multiplication, so like this, and you will see the result of the multiplication
of these two, so it's 54. Also you can do for example division, so if you divide these two numbers, let me run this
and what will be the result, now you can see it's 1
Also you can find the remainder or modulus of these two numbers, so for example I want
to find the remainder or modulus of this or mod of these two numbers, so if you divide
9 divide 6, the remainder will be 3. So now let me just run this, and now you can see we are receiving 3
Now like this you can use variables in C++ programming language, if you have any question
please let me know, and for the further videos please subscribe to my channel and also like this video