字符 - ASCII 关系 [英] Char - ASCII relation
问题描述
C 编程语言中的 char 是一个固定大小的字节实体,专门设计为足够大以存储来自 ASCII 等编码的字符值.
A char in the C programming language is a fixed-size byte entity designed specifically to be large enough to store a character value from an encoding such as ASCII.
但是与 ASCII 编码相关的整数值在多大程度上可以与 char 字符互换?有没有办法将A"称为 65(十进制)?
But to what extent are the integer values relating to ASCII encoding interchangeable with the char characters? Is there any way to refer to 'A' as 65 (decimal)?
getchar() 返回一个整数 - 大概这与这些值直接相关?另外,如果我没记错的话,在某些情况下可以增加字符......这样(粗略地说)'?'+1 == '@'.
getchar() returns an integer - presumably this relates directly to such values? Also, if I am not mistaken, it is possible in certain contexts to increment chars ... such that (roughly speaking) '?'+1 == '@'.
或者这样的编码不能保证是ASCII?它是否完全取决于特定的环境?这种对字符的操作在 C 中是不切实际的还是不可能的?
Or is such encoding not guaranteed to be ASCII? Does it depend entirely upon the particular environment? Is such manipulation of chars impractical or impossible in C?
相关:C比较char和int
推荐答案
但是与 ASCII 编码相关的整数值在多大程度上可以与 char 字符互换?有没有办法将A"称为 65(十进制)?
But to what extent are the integer values relating to ASCII encoding interchangeable with the char characters? Is there any way to refer to 'A' as 65 (decimal)?
事实上,你无能为力.char
只是一个整数类型,如果你写
In fact, you can't do anything else. char
is just an integral type, and if you write
char ch = 'A';
那么(假设 ASCII),ch
将只保存整数值 65
- 将它呈现给用户是一个不同的问题.
then (assuming ASCII), ch
will merely hold the integer value 65
- presenting it to the user is a different problem.
或者这样的编码不保证是ASCII?
Or is such encoding not guaranteed to be ASCII?
不,不是.C 不依赖于任何特定的字符编码.
No, it isn't. C doesn't rely on any specific character encoding.
它是否完全取决于特定的环境?
Does it depend entirely upon the particular environment?
是的,差不多.
这种对字符的操作在 C 中是不切实际的还是不可能的?
Is such manipulation of chars impractical or impossible in C?
不,您只需要小心并充分了解标准 - 这样您就安全了.
No, you just have to be careful and know the standard quite well - then you'll be safe.
这篇关于字符 - ASCII 关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!