Char data type in C
In this article, I am going to discuss Character Data Types in C programming with Examples. You can read my previous article where I've discussed All Data Types in C programming in short.
At the end of this article, you will understand everything about character data type in c language.
Character Data Types in C Language
Char Data Type is used to store single character in variable. char type of variable acquires 1 byte of memory in memory.
The character data type is divided into two types, one is signed data type and the second one is unsigned data type.
Both signed char data type and unsigned char data type acquire 1 byte of memory. Unsigned means it will accept only positive values and the signed means it will accept both positive as well as negative values. Whatever the type either signed or unsigned, the character occupies only one byte.
Using 1 byte of memory what is the minimum and maximum value we can store?
To understand this, look at the memory allocation process. Here I am taking 1 byte of memory. 1 byte equals 8 bits. And it takes only binary values i.e. 0 and 1.
So, using 1 byte of memory, the minimum integer value we can store is 0 and the maximum integer value we can store is 255.
Unsigned Character Range in C Language:
As we already discussed unsigned means it will accept only positive values. And the range 28 equals 256. As positive value starts with 0, so, the unsigned character data type range is from 0 to 255.
Signed Character Range in C Language:
Now let us understand the range of Signed character data types. The signed data type accepts both positive as well as negative values. So, we need to divide 28 = 256 by 2. 256/2 the value is 128. So negative values start with -1, -2, and up to -128 and the positive values start from 0 up to 127.
We are using character data type to store symbols like a, b, A, B, or some special symbols.
Now the question arises, how can we represent such symbols in integers? Why character data type representation in integer. So, while working with Character Data Types in C Language, we need to understand the following four questions:
- Why does character limits representation in integers?
- How can we store symbols into one-byte memory nothing but why character occupies one-byte memory?
- What is a character system?
- What is ASCII? Read More...
Original Credit: www.dheerajpatidar.com
Subscribe to my newsletter
Read articles from Dheeraj Patidar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Dheeraj Patidar
Dheeraj Patidar
In this site I'm presenting the content about digital marketing, online jobs, programming languages, and other technical aspects.