char 和 unsigned char 有什么区别? [英] What is the difference between char and unsigned char?
问题描述
(已编辑将 C/C++ 更改为 C)
请帮我找出一个关于C中char
和unsigned char
的清晰说明.特别是当我们在嵌入式设备和普通PC之间传输数据时(缓冲区之间的区别unsigned char
和普通 char
).
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
).
推荐答案
你问的是两种不同的语言,但在这方面,答案(或多或少)对两者都是相同的.不过,您确实应该决定使用哪种语言.
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.
区别:
- 它们是不同的类型
char
是有符号还是无符号由实现定义
- they are distinct types
- it's implementation-defined whether
char
is signed or unsigned
相似之处:
- 它们都是整数类型
- 它们的大小相同(一个字节,至少 8 位)
如果您只是使用它们来传输原始字节值,没有算术,那么没有实际区别.
If you're simply using them to transfer raw byte values, with no arithmetic, then there's no practical difference.
这篇关于char 和 unsigned char 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!