阵列K&安培; R 1.6个字符? [英] Arrays K&R 1.6 chars?

查看:156
本文介绍了阵列K&安培; R 1.6个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在K&放大器23页; R第二版,有一些code

on page 23 in the K&R second edition, there is some code

    if (c >= '0' && c <= '9')
       ++ndigit[c-'0'];

如此下去。我的问题是,为什么整数有'每边?
什么是C-'0?

It goes on. My question is, why do the integers have the ' on each side? and what is the c-'0'?

推荐答案

在code的目的是为了在字符转换 0'...' 9'到相应的整数 0 ... 9 。 C那样被不可以保证字符重新presenting十进制数字有什么特别的价值,但它的确实保证它们是连续的,并以正确的顺序。减法以上将永远给你正确的整数值。

The purpose of the code is to convert the characters '0'...'9' into the corresponding integer values 0...9. C does not guarantee that the characters representing decimal digits have any particular value, but it does guarantee that they are consecutive and in the correct order. The subtraction above will always give you the correct integer value.

有是在C任何其它​​字符没有类似的保证。

There is no similar guarantee for any other character in C.

在ISO 9899:1999标准(又称C99)说:

The ISO 9899:1999 Standard (aka C99) says:

执行字符集的成员的值是实现定义的。 ...

The values of the members of the execution character set are implementation-defined. ...

设置为0,所有位字节,称为空字符,应在基本执行字符集存在;它用于终止字符串。 ...

A byte with all bits set to 0, called the null character, shall exist in the basic execution character set; it is used to terminate a character string. ...

每个字符的十进制数字上面的列表0后的值应大于previous价值较大者。

the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous.

完全相同的措辞在 N1570 ,这是当前的标准(C11),最后公开草案

Exactly the same wording is found in N1570, which was the final public draft of the current standard (C11).

别的不多说关于字符之间的值,或关系。

Not much else is said about the values of, or relationship between characters.

这篇关于阵列K&安培; R 1.6个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆