There are 3 character types: signed char unsigned char char (yes, this is indeed a distinct type, not "alias", but for practical purposes it is the same as one of the above two, implementation specified) sizeof for these is defined to be 1. Using sizeof char is always redundant, though it can be used like a comment, making code more clear. On any platform you are likely to ever work on, char is 8 bits, and synonym to "byte". Therefore, int8_t is probably signed char and uint8_t is unsigned char typedefs. Answer from Deleted User on reddit.com
🌐
Medium
medium.com › @mazen.elheni › unsigned-char-in-c-with-examples-efa3db909c71
Unsigned char in C with Examples. char is the most basic data type in C… | by Mazen Elheni | Medium
February 5, 2025 - char is the most basic data type ... almost all compilers. ... 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)....
🌐
GeeksforGeeks
geeksforgeeks.org › c language › unsigned-char-in-c-with-examples
unsigned char in C with Examples - GeeksforGeeks
July 12, 2025 - Now character datatype can be divided into 2 types: ... 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).
Discussions

c - Difference between signed / unsigned char - Stack Overflow
Closed 8 years ago. So I know that the difference between a signed int and unsigned int is that a bit is used to signify if the number if positive or negative, but how does this apply to a char? More on stackoverflow.com
🌐 stackoverflow.com
c++ - Char and unsigned char - Software Engineering Stack Exchange
Where is unsigned char used in C ( please tell about some real-world examples )? Why would we need both char and unsigned char? Char ranges from -127 to 128 ( 8-bit integer ) Unsigned Char ranges ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
May 22, 2013
c++ - What is an unsigned char? - Stack Overflow
In C/C++, what is an unsigned char used for? How is it different from a regular char? More on stackoverflow.com
🌐 stackoverflow.com
What's difference between unsigned char and signed char ?
In 8 bit micro an unsigned type can only represent positive values where as a signed type can represent both positive and negative values. In the case of a 8-bit char this means that an unsigned char variable can hold a value in the range 0 to 255 while a signed char has the range -128 to 127. More on forum.allaboutcircuits.com
🌐 forum.allaboutcircuits.com
12
April 15, 2020
Top answer
1 of 3
6

Where is unsigned char used in C ( please tell about some real-world examples )? Why would we need both char and unsigned char?

signed or unsigned are properties of the different C data types (char, short, int, etc...). So it's not a question of whether we need both, both come automatically as part of how C is defined.

Char ranges from -127 to 128 ( 8-bit integer ) Unsigned Char ranges from 0 to 255 ( 8-bit integer )

While that's true for most of the platforms out there, there's nothing garanting that char will be signed. In fact on ARM platforms, it's unsigned. See this fix: http://www.spinics.net/lists/linux-btrfs/msg20653.html as an example of real-world bug introduced by assuming that char is signed.

If the purpose is to store ASCII, why would we need both?

The thing is, the purpose is not to store ASCII. It happens to be used to store ASCII but it's a not a necessity.

char a = 127;

unsigned char b = 255;

When I print it using std::cout. It gives me different characters. Can you explain why? ( I'm using Microsoft vs11 compiler

I think what you're looking for is the following:

#include <iostream>

int main(void)
{
        char a = -1; 
        unsigned char b = 255;
        std::cout << a << std::endl << b << std::endl;
        return 0;
}

That is '-1' signed will be equal to '255' unsigned. Please note that this is heavily implementation dependent, and there's nothing that guarantees it will work accross all platforms and compilers.

2 of 3
7

unsigned char stores a number. You can use it when you need to represent numbers in the range 0 to 255 and want to conserve memory.

🌐
w3resource
w3resource.com › c-programming-exercises › c-snippets › what-is-an-unsigned-character-in-c.php
What is an unsigned char in C with examples and usage
November 1, 2025 - In C programming, unsigned char is a data type used for storing small, non-negative integer values.
Find elsewhere
🌐
Sololearn
sololearn.com › en › Discuss › 2181227 › char-and-unsigned-char-in-c
char and unsigned char in C | Sololearn: Learn to code for FREE!
February 24, 2020 - If sc=200, means if exceeds 127, then next value is equal to -128. So it repeats.. Since 01111111 +1 10000000 2's compliment of this gives you equal positive value and 256 200 ------ 56 if you assign signed char c=200, it stored as singned char c=-56, => equal to unsigned char c=200
Top answer
1 of 16
629

In C++, there are three distinct character types:

  1. char
  2. signed char
  3. unsigned char

1. char

If you are using character types for text, use the unqualified char:

  • it is the type of character literals like 'a' or '0' (in C++ only, in C their type is int)
  • it is the type that makes up C strings like "abcde"

It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through inequalities - although if you limit yourself to ASCII (0-127) you're just about safe.

2. signed char/ 3. unsigned char

If you are using character types as numbers, use:

  • signed char, which gives you at least the -127 to 127 range. (-128 to 127 is common)
  • unsigned char, which gives you at least the 0 to 255 range. This might be useful for displaying an octet e.g. as hex value.

"At least", because the C++ standard only gives the minimum range of values that each numeric type is required to cover. sizeof (char) is required to be 1 (i.e. one byte), but a byte could in theory be for example 32 bits. sizeof would still be report its size as 1 - meaning that you could have sizeof (char) == sizeof (long) == 1.

2 of 16
106

This is implementation dependent, as the C standard does NOT define the signed-ness of char. Depending on the platform, char may be signed or unsigned, so you need to explicitly ask for signed char or unsigned char if your implementation depends on it. Just use char if you intend to represent characters from strings, as this will match what your platform puts in the string.

The difference between signed char and unsigned char is as you'd expect. On most platforms, signed char will be an 8-bit two's complement number ranging from -128 to 127, and unsigned char will be an 8-bit unsigned integer (0 to 255). Note the standard does NOT require that char types have 8 bits, only that sizeof(char) return 1. You can get at the number of bits in a char with CHAR_BIT in limits.h. There are few if any platforms today where this will be something other than 8, though.

There is a nice summary of this issue here.

As others have mentioned since I posted this, you're better off using int8_t and uint8_t if you really want to represent small integers.

🌐
C2lang
c2lang.org › forum › index.php
Unsigned char
C2 forum · News: · SMF - Just Installed · Search · Login · Register · C2 forum » · General Category » · Ideas » · Unsigned char
🌐
AVR Freaks
avrfreaks.net › s › topic › a5C3l000000UbM3EAK › t157383
unsigned char in c
February 27, 2020 - Loading · ×Sorry to interrupt · Refresh
🌐
Scaler
scaler.com › home › topics › what is an unsigned char in c++?
What is an unsigned char in C++? - Scaler Topics
May 19, 2024 - In C++, a data type known as an unsigned char only handles positive values between 0 and 255. The unsigned char is limited to non-negative integers, unlike its signed cousin, which may store both positive and negative numbers.
🌐
Medium
medium.com › analytics-vidhya › what-is-char-signed-char-unsigned-char-and-character-literals-in-c-796034139b98
What is char , signed char , unsigned char , and character literals in C? | by mohamad wael | Analytics Vidhya | Medium
February 26, 2024 - The unsigned char type can only store nonnegative integer values , it has a minimum range between 0 and 127 , as defined by the C standard. The signed char type can store , negative , zero , and positive integer values .
🌐
Quora
quora.com › When-would-you-want-to-use-unsigned-char-versus-signed-char-Is-it-to-access-a-different-ASCII-symbol
When would you want to use unsigned char versus signed char? Is it to access a different ASCII symbol? - Quora
Answer (1 of 4): In the C programming language, [code ]char[/code] is an integer type that represents the minimal addressable storage unit. The language standard calls this a byte. On most computers, this is an 8-bit value. It’s not required to be. I’ve worked with a machine for which [code ]cha...
🌐
LinuxQuestions.org
linuxquestions.org › questions › programming-9 › unsigned-char-in-c-language-303608
unsigned char in C language
March 19, 2005 - Ok i created this form question because i asked this in another post witch was wrong to do. So I ask all of the programming guru out there what is a
🌐
All About Circuits
forum.allaboutcircuits.com › home › forums › embedded & programming › programming & languages
What's difference between unsigned char and signed char ? | All About Circuits
April 15, 2020 - In 8 bit micro an unsigned type can only represent positive values where as a signed type can represent both positive and negative values. In the case of a 8-bit char this means that an unsigned char variable can hold a value in the range 0 to 255 ...
🌐
Cprogramming
cboard.cprogramming.com › cplusplus-programming › 149746-whats-point-unsigned-char.html
What's the point of unsigned char?
July 13, 2012 - Besides, using int is usually the best choice, as it's the native word size, meaning basically that it's the fastest size that your particular machine can manipulate. ... An unsigned char can hold any value from 0 to 255, and if you assign it the value 222 say, then it has the value 222, regardless ...
🌐
IME USP
ime.usp.br › ~pf › algorithms › chapters › int-and-char.html
What is a signed int? an unsigned int? a char?
In C language, the natural numbers are known as unsigned integers, while the integer numbers are known as signed integers. Unsigned integers are implemented by the data types unsigned char and unsigned int. Signed integers are implemented by the data types char and int.
🌐
Quora
quora.com › How-is-unsigned-char-data-type-used-in-embedded-c-for-8-bit-microcontroller-as-a-decimal-integer-value-not-a-char-value
How is 'unsigned char' data type used in embedded c for 8 bit microcontroller as a decimal/integer value, not a char value? - Quora
Answer (1 of 13): From the beginning of time in C, whether you’re in a microcontroller environment or not, the char data type has always been usable as a one-byte integer. You can use a char variable to store the ASCII (or some other encoding’s) value of a character, or you can use it simply as a...
🌐
Quora
quora.com › When-should-we-use-unsigned-char-versus-char-in-C-language
When should we use unsigned char versus char in C language? - Quora
Answer (1 of 9): Any time you don’t expect an integral value to be less than zero, it is appropriate to declare it unsigned to document that fact. In C, many functions take int arguments that are never negative. You should declare as int anything you want to pass to a function taking an int argu...