declare

Variables Declaration and Usage in C Programming | Video Tutorial



Sharing buttons:

hi this is Anil BW tutorial for the

learning latency programming so in this

video tutorial we're gonna see what is a

variable and how we can declare our

variable n see how we can as in awhile

to that variable and how we can retrieve

the values from that variable so let's

get started or if you know that you know

a variable is a name given to a memory

location so in C if you want to use a

variable you have to declare it so first

we're gonna see how we can declare a

variable so first we have to write the

type of data you want to store in that

variable if you want to store an integer

data in that variable then you have to

write int or if you are storing a

floating-point number then you have to

write float and if are adding a

character data or a character then you

have to write cat so that is called the

data type so it just indicates what type

of data will be stored in that variable

so here first let me show you the syntax

first it's gonna be data type then the

name of the variable then a semicolon

that's it this is how you can declare a

variable so first here for the

demonstration purpose we're gonna create

three variables so first I want to store

my age so my age is a whole number and

you know it's an integer value that's

why I'm gonna write int that's because

you know I'm storing integer data in

that variable then the way of name so

I'm gonna call it H if you want to give

it any other name you can do that no

problem so then I want to store my

weight so my weight is fifty point five

so it's a floating point data that's why

I'm gonna write float then weight

so the next one is I want to show my sex

that's why I'm gonna write care and the

name of the variable is sex that's it

now we have three variables or we have

defined you know three variables here so

now what we wanna do is we want to add

in some value to these variables so two

as I know where it to a variable we're

going to use the assignment operator so

first you have to write the variable

name so so here first we want to assign

a value to this variable age so this way

I'm gonna write age then the assignment

operator then the value you want to

store in that variable so I wonder store

my age that is 23 that's it a semicolon

so next we want to store my weight it's

going to be weight and as an operator

then 50.5 so next I um disturb my sex

it's gonna be SC X equal to in single

course we have cried M that's because

you know as a character constant is

written in single quotes so this is it

so we have you know and declared our

variables and we have assigned the

values to its variables so the last

thing we want to do in this tutorial is

we just want to print out the values

stored in its variables so that's why we

can I use the printf statement and

in printf statement we can use the

format specifier you know which

specifies the type of data is referenced

so first we want to print the data or

value stored in this age variable so

that's why you know this ad sub type

integer you have to write the format

specifiers % 8d then leave a space and

then we want to print the data which is

stored in this variable weight and this

weight variable is up type float that's

why we have to write the format

specifier percentage F then I'm gonna

leave a space then we want to print the

data stored in this variable sex and

this variable sets is of type character

that's why we need to specify format

specifiers percentage c so then we need

to refer the variables corresponding to

this format specifiers so first we

referred about age variable then the

weight then the sex so this is it I'm

gonna save it compile it and run it

so as you can see here we just printed

23 that's my age then fifty point five

zero zero zero

that's my weight and M that's my sex so

this is it this is about the variable

and how we can define as in and retrieve

the value from the variables so thanks

for watching and don't forget to

subscribe I see in the next tutorial