Character data type in C.

Hello coders! Welcome back!

Today we are looking into character data type in C.

As integer data types are declared and initialized. Similarly, the character data type can be initialized and declared.

You can have a look at how integers are declared and initialized, click here

By referring to the above blog we can declare character data type as-

char varr; 

Let's see how to initialize the character data type-

char varr = 'V';

Here are a few points to look at, always initialize a character that you want to display in single quotes. A character cant print the entire string.

You can also mention the ASCII number of a particular character you want to display. Let's look into the ASCII table.

So, let's see what this table gives us the information. If we want to print caps 'A' the ASCII code is
65. So, we initialize the character variable with 65. let's look into the program what happens it will display-

It's printing A in the command prompt.

The size of the character is 8 bit. The range of unsigned characters is from 0 to 255. And the range of signed character is from -128 to 127.

You might get a doubt about what negative values indicate in character. To get the answer we should look into the extended ASCII table.

So, in extended ASCII table 128 corresponds to alphabet C. Now let's see what happens if we initialize -128 and +128 to the code -









Hence when you give -128 & 128 it prints the same character 'C'.

let's look into the explanation-

The binary representation of 128 and -128 is the same.

After all its matter of binary representation. Because the computer can understand only binary representation.

The signed character is equivalent to some positive numbers in the extended ASCII table.

I hope so, you got clear idea about the signed character. If any doubts drop a comment.

Happy learning!!



Comments

Popular post