C Programming Tutorial 25 - Char Data Type

Sharing buttons:

welcome back everyone to Caleb the video

maker to this video we are going to

explore the char data type so let's

create a new file we'll just name this

char dot C and you know we'll do the

standard include us standard i/o alright

so how do we make a character variable

well we just say char and then we give

it a name and then we can give it a


now remember when we're working with

characters we always want to use single

quotes so something needs to go inside

of those single quotes but what let's

use capital a just so we can become

familiar with one character this is the

one we used in the previous video and we

learned that the integer value for a is

actually 65 and I want to prove that to

you in this video so you know I'm not

just making something up let's learn to

print characters to the screen we are

still going to use the printf function

but we are going to learn a new

conversion character specifically it is

percent C and then we'll go to a new

line and what are we going to print

we're gonna print X that's a

particularly confusing variable name

because it's a character itself I want

to make sure there's not confusion I

don't want people to think hey I'm going

to print the value X instead I'm going

to rename this to something else

my character or my char now it's a

little less confusing now let's run this

make sure it works and you can see

outputs the character a just like we

wanted now how do we actually take input

of characters well I'm going to show you

that let's go back to our code and in

here we're going to declare the char

variable but we're not going to

initialize it and now we are going to

use the scanf function and in here we

are going to pass in % C just like you

would expect the variable we are going

to put it in is with the address of

operator my char let's try this when we

output it it'll ask us for a character

even though it doesn't say anything we

never put a prompt but let's try our and

outputs are so it's working well what


do you need to know well to be honest

there's really not a whole lot to it

there is one thing I wanted to share

with you guys and that is the ASCII

table this is the ASCII value for every

single character that we can use inside

of ASCII and inside of the console you

can see here this is capital a and it

has the value of 65 as you can see the

decimal version is 65 right there now if

you wanted to classify these things

because I know some of you guys love

classifications you could say that the

first section of characters are called

control characters only a few of those

are going to be useful for us

I'd also group the last one in here

these codes were for controlling devices

such as printers they're really not used

so much today

there are a couple that will be useful

for us for example tab the null

character and I'm sure there's a couple

others we might run into the rest of

them these are considered the printable

characters these are the ones we could

actually see the second table down here

is called the extended ASCII codes

that's what I was explaining in the last

video where in some situations that most

significant bit will be used and this

will allow us to have more options in

the next video we are going to create a

program that will actually convert

between integers and ASCII by the end of

that video you'll see how easy it is to

work with ASCII so be sure to check that

out guys if you've liked this video

please click Subscribe

click like and check out the next video

thanks guys and I'll see you then