00:00:00
hey guys welcome back to this series on
00:00:02
C programming in this video we will be
00:00:04
learning about variables more
00:00:06
specifically we will learn how to create
00:00:08
variables and store data in them so that
00:00:10
we can use them later in our program so
00:00:13
let's get
00:00:17
started in computer programming a
00:00:20
variable is a name given to a memory
00:00:22
location inside our computer where we
00:00:24
can store data let me give you an
00:00:26
example I will go to my compiler here
00:00:28
you can see int is here the name of the
00:00:31
variable is is and to create this
00:00:34
variable we use this keyword int this
00:00:36
int keyword is a data type which
00:00:38
indicates that the a variable can only
00:00:41
store integer values in C programming
00:00:44
every variable must have a type like
00:00:46
this int we will learn about these data
00:00:48
types in detail in next video and in
00:00:50
this video we will continue using int to
00:00:53
create our variables once we create a
00:00:55
variable like this in a we can also
00:00:58
store data into it like is equals to 25
00:01:03
here we have first created a variable
00:01:05
named is and then we have assigned an
00:01:07
integer value 25 to this a variable by
00:01:11
the way we have to use this semicolon at
00:01:14
the end to Mark the end of this
00:01:16
statement and it is also possible to
00:01:19
create variable and assign value in a
00:01:21
single line let me show you how so
00:01:23
instead of writing these two lines of
00:01:25
code we can just merge them and write a
00:01:28
single line of code like this so I'll
00:01:31
cut this
00:01:32
out if you have watched the last video
00:01:35
we have used a structure that every C
00:01:37
program follows I'll get back to my
00:01:39
compiler if you remember this is the
00:01:42
basic structure of C program so now
00:01:45
let's add a variable inside this main
00:01:49
function int is equals to
00:01:54
25 if we run this code a variable is
00:01:57
created but we'll not see any output and
00:02:00
to get output in C programming we will
00:02:03
use printer function before we print
00:02:06
this variable let's first try to print a
00:02:08
normal text then in the next step we
00:02:10
will learn to print variables now to
00:02:13
print a line of text we use the print
00:02:16
function print F bracket inside
00:02:20
quotation C
00:02:25
programming and we will always end the
00:02:28
statement with a semicolon
00:02:30
now let me run this code and we can see
00:02:34
C programming is printed on the screen
00:02:37
by the way our variable a is also
00:02:39
created but we haven't seen it because
00:02:41
we haven't printed it now let's print
00:02:43
our variable I just want to print a
00:02:46
variable so I'll cut this part that
00:02:48
prints a line of text then I'll write
00:02:51
print F bracket inside
00:02:54
quotation percent D comma and the name
00:02:58
of the variable in this case the name of
00:03:00
the variable is is to print a variable
00:03:03
in C programming we use something called
00:03:06
format specifier here person D is a
00:03:10
format
00:03:10
specifier now let's run this
00:03:14
code as we can see 25 is printed as an
00:03:18
output so what happens here is that here
00:03:22
person D is replaced by the value of a
00:03:24
variable if we have to print other data
00:03:27
like characters and decimals we use
00:03:29
different specifier like percent C and
00:03:31
percent F which we will discuss in the
00:03:34
next video let me modify this program a
00:03:37
bit here I'll write
00:03:39
here is colon now let me run this code
00:03:44
again now we can see this a column is
00:03:48
printed as it is and person D is
00:03:50
replaced with the value of
00:03:55
a now that we know how to store data in
00:03:58
variables let's see see how we can
00:04:00
change their values yes we can change
00:04:02
the values of variable that's why it is
00:04:05
called variable let me give you an
00:04:07
example I'll go back to my previous
00:04:09
example currently the a variable stores
00:04:12
25 now I'll assign a new value to this a
00:04:16
variable a is equal to 31 and I'll print
00:04:23
this new is
00:04:27
semicolon percent D and and comma and
00:04:31
again a and end this with semicolon
00:04:34
let's run this
00:04:35
program as you can see initially the
00:04:38
value of a was 25 then I changed the
00:04:40
value of a by assigning 31 now let me
00:04:43
put this second line of code into a new
00:04:46
line for that I'll use back sln and I'll
00:04:50
run this again and you can see the
00:04:52
output it is more readable and more
00:04:55
clearer so here this back sln is a new
00:04:58
line character simply speaking it is a
00:05:01
inter
00:05:03
key so far we saw that we can assign
00:05:06
data directly to a variable however we
00:05:09
can also assign a value of one variable
00:05:11
to another let me show you an example in
00:05:14
this example as you can see we have
00:05:16
assigned value 33 to this first number
00:05:19
variable and we have then printed this
00:05:21
first number variable now I'll assign
00:05:24
another variable second number
00:05:30
and instead of assigning any data I'll
00:05:33
assign here first
00:05:37
number then I'll print
00:05:41
this back sln so that we can get a
00:05:44
readable
00:05:46
output second
00:05:48
number equals to perc
00:05:51
D and name of the variable that is
00:05:54
second
00:05:57
number now let's see what will happen
00:06:00
I'll run this
00:06:02
code and we can see first number and
00:06:05
second number variable holds the same
00:06:07
value 33 let's see how this program
00:06:10
works line by line first we have created
00:06:12
this variable first number and assigned
00:06:15
value 33 to it then we have printed this
00:06:18
variable and then we assigned another
00:06:21
variable second number and assigned the
00:06:23
value of the first number to it then we
00:06:25
have printed the second number
00:06:31
we can also declare multiple variables
00:06:33
in a single line let me give you an
00:06:35
example here I have created two
00:06:37
variables variable one and variable two
00:06:40
and I have separated them with the comma
00:06:42
in a single line let me modify this
00:06:45
program a bit I'll assign a value 25 to
00:06:48
this variable too here the same two
00:06:50
variables are created however the value
00:06:53
of variable 2 is now 25 by the way in C
00:06:57
programming if we do not assign a value
00:06:59
to a variable its value cannot be
00:07:01
determined in this program variable one
00:07:03
will have some random unpredictable
00:07:05
value however some compilers may store
00:07:08
Jero in them okay guys we need your
00:07:11
support to keep this type of content
00:07:13
free for all users YouTube really likes
00:07:16
engagement on the video so leave a
00:07:18
comment below press that like button and
00:07:20
hit subscribe if you haven't already
00:07:22
let's get the engagement score high up
00:07:25
so that more people can discover and
00:07:27
enjoy these courses
00:07:31
at this point we have covered all the
00:07:33
basics of variable before ending this
00:07:35
video let's talk about how to choose a
00:07:37
good variable name if you have noticed I
00:07:40
have used descriptive variable names
00:07:42
like a and first number we could have
00:07:44
given variable names like a instead of
00:07:47
A's and FN instead of first number it
00:07:50
works just fine however it's hard to
00:07:53
understand what a means just by looking
00:07:55
at the code so when we use good
00:07:58
descriptive variable names it becomes
00:08:00
easier to understand the code and to
00:08:02
make the variable name descriptive we
00:08:05
may need to use names having more than
00:08:07
one word in such cases we follow the
00:08:09
camel case format while giving the names
00:08:11
to the variable in camel case the first
00:08:14
word will be of small letter and the
00:08:16
first letter of the second word will be
00:08:18
of capital letter like the example shown
00:08:20
on the screen by the way there are some
00:08:23
rules you need to know while creating a
00:08:25
variable you cannot create variable
00:08:27
names with space in between you cannot
00:08:30
start variable names with numbers and
00:08:33
you cannot use certain words as variable
00:08:35
names you cannot use if as a variable
00:08:38
name because if is a keyword these
00:08:40
keywords are part of C programming
00:08:42
syntax and have special meaning in C we
00:08:45
will learn about these keywords as we
00:08:47
progress through the course and now we
00:08:49
are at the end of this video it's time
00:08:52
for programing quiz can you guess the
00:08:54
output of this program comment your
00:08:57
answer below and I'll see you in the
00:08:59
next video video Happy programming
00:09:04
[Music]