What is the difference between char and unsigned char?

Dig The Code picture Dig The Code · Mar 25, 2014 · Viewed 10k times · Source

(Edited change C/C++ to C)

Please help me to find out a clean clarification on char and unsigned char in C. Specially when we transfer data between embedded devices and general PCs (The difference between buffer of unsigned char and plain char).

Answer

Mike Seymour picture Mike Seymour · Mar 25, 2014

You're asking about two different languages but, in this respect, the answer is (more or less) the same for both. You really should decide which language you're using though.

Differences:

  • they are distinct types
  • it's implementation-defined whether char is signed or unsigned

Similarities:

  • they are both integer types
  • they are the same size (one byte, at least 8 bits)

If you're simply using them to transfer raw byte values, with no arithmetic, then there's no practical difference.