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!!
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmmzi2r5ASybPyWZ_EYBk-Ce22II6YR5oo4I56Ny0tSlLyrtVNFxXtitwQUPRI5XW6tcoO9UpWTO3B8DpQ1gPL3oVuGWittErxLwLUJaLlm5wrN81ecgZNUvI-ykrykBjWEQO4AqPUGro/s640/738px-ASCII-Table.svg.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh09HzbUzW5_XC4bWvI9FwN8_27b5PsGMQztjn_KWjN9TO1J_sPak6zL80FsBbNupbdq1KYhL8OtOwUOEUIpRrm6DiQpgiF0oAHgNmuqd19NfbTLfTs5gr-usi74jWLaGEpEZmK7kF4os/s640/Untitled.png)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDCS4_IN_gJFPag1ShuL5HE7nfrAnvOk9iPD7P7FFP1tleFkq85EIFfB3yr_PemTpo1PhkiJRLUkeptapbZykgrCax9zopZZOpG7giHMWNaHs0RVdZtEZpshdGYIbnrNWyO0xwg25iqPc/s640/screen_shot_2019_12_01_at_3.26.20_pm-34867850.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid0dsEjVpBoRJu9uqqvW0r2_CWTQ5gOiWhocv9eVE0N2eF6zs_qdYWVFF-Gb25B1yyi50G0pMTdeLbvDCbeop8K7vyvPFGp29h5lqrItDvm14Sh15FoZRlIvheHe-OvLXBUXik6t2IkNo/s640/2.png)
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
Post a Comment