char is the most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.
Now character datatype can be divided into 2 types:
- signed char
- unsigned char

unsigned char is a character datatype where the variable consumes all the 8 bits of the memory and there is no sign bit (which is there in signed char). So it means that the range of unsigned char data type ranges from 0 to 255.
Syntax:
unsigned char [variable_name] = [value]
Example:
unsigned char ch = 'a';
- Initializing an unsigned char: Here we try to insert a char in the unsigned char variable with the help of ASCII value. So the ASCII value 97 will be converted to a character value, i.e. ‘a’ and it will be inserted in unsigned char.
// C program to show unsigned char#include <stdio.h>intmain(){intchr = 97;unsignedchari = chr;printf("unsigned char: %c\n", i);return0;}chevron_rightfilter_noneOutput:unsigned char: a
Initializing an unsigned char with signed value: Here we try to insert a char in the unsigned char variable with the help of ASCII value. So the ASCII value -1 will be first converted to a range 0-255 by rounding. So it will be 255. Now, this value will be converted to a character value, i.e. ‘ÿ’ and it will be inserted in unsigned char.
// C program to show unsigned char#include <stdio.h>intmain(){intchr = -1;unsignedchari = chr;printf("unsigned char: %c\n", i);return0;}chevron_rightfilter_noneOutput:unsigned char: ÿ
Recommended Posts:
- Set value of unsigned char array in C during runtime
- size of char datatype and char array in C
- C/C++ program to find the size of int, float, double and char
- time.h header file in C with Examples
- time.h localtime() function in C with Examples
- Arrow operator -> in C/C++ with Examples
- Pointer Expressions in C with Examples
- <complex.h> header file in C with Examples
- getch() function in C with Examples
- std::string::crbegin() and std::string::crend() in C++ with Examples
- Pointer Arithmetics in C with Examples
- Difference between NULL pointer, Null character ('\0') and '0' in C with Examples
- Exit codes in C/C++ with Examples
- Unspecified behavior in C/C++ with Examples
- dos.h header in C with examples
- How to find arctangent with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Zero97M

