Home »
C programs
‘unsigned char’ - Declaration, Assign and Usage in C programming
Here, we are going to learn about unsigned char: why, where and how it is used? We are demonstrating use of unsigned char through an example in C programming language.
Submitted by IncludeHelp, on May 05, 2018
char is a data type in C programming language which can store value from -128 to +127. It generally used to store character values.
unsigned is a qualifier which is used to increase the values to be written in the memory blocks. For example - char can store values between -128 to +127, while an unsigned char can store value from 0 to 255 only.
unsigned store only positive values, its range starts from 0 to (MAX_VALUE*2)+1.
unsigned char is a character data type with larger range of the value than signed char.
Whenever we work with positive value between the range of 0 to 255, we can use unsigned char instead of short, int type of data type.
Declaration syntax:
unsigned char variable_name;
Declaration example:
unsigned char age;
Program to read and print the unsigned char value in C
#include <stdio.h>
int main()
{
unsigned char age;
printf("Enter age: ");
scanf("%d",&age);
printf("Input age is: %d\n",age);
return 0;
}
Output
Enter age: 75
Input age is: 75