又回到C了,苦逼的我,绕了一大圈,又回到了起点,(ˇˍˇ) 想~当年老师的苦口婆心,恨少年的轻狂,最终还是那句话,欠的债总是要还的,好啦,叨唠了一番,言归正传。
今天看了下C界的达摩圣书<C程序设计语言>,就是K&R写的那本,读了第一张,果不其然,确实是一本好书,讲的很全面,例如变量命名规范,这里为什么变量命名开头除了字母还有underscore,来,我们来看下面这句话“C language, developed at Bell Labs in the early 1970s, allowed the underscore as an alphabetic character.",哈哈,看到这句话大家会焕然大悟了吧,其实下划线在C中也是被认为是一个alphabetic,也就是字母字符,这是为什么呢,我们再来看看
The Standard requires that an alphabet of 96 symbols is available for C as follows:
a b c d e f g h i j k l m n o p q r s t u v w x y z |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
0 1 2 3 4 5 6 7 8 9 |
! " # % & ' ( ) * + , - . / |
: ; < = > ? [ \ ] ^ _ { | } ~ |
space, horizontal and vertical tab |
form feed, newline |
Table 2.1. The Alphabet of C
大家看到了吧,C语言中定义了96符号作为英文字母(注意:这与我们平常认为的英文字母只有26个是不一样的),他们在ASCII码的什么位置呢,再来看看下面这句话:
The ASCII codes (American Standard Code for Information Interchange) used the numbers from 32 to 127 to represent characters of the English alphabet. These 96 codes corresponded to the upper and lower case alphabet, the numerals, and the most useful symbols for punctuation.
也就是32到127代表了英文字母,而变量命名规定只能用52个大小写字母、以及10个数字,和下划线,原话如下:
The rules for the construction of identifiers are simple: you may use the 52 upper and lower case alphabetic characters, the 10 digits and finally the underscore ‘_
’, which is considered to be an alphabetic character for this purpose. The only restriction is the usual one; identifiers must start with an alphabetic character.
大家现在明白了吗,为什么变量可以以下划线开头,但是这边为什么变量取名只能包含字母、数字或下划线,而不能包含其他字符,这个我就不清楚了,书本没说,好啦,这就是今天看第一章的一点小心得,明天继续,A~ZA
附注:Reference link:http://publications.gbdirect.co.uk/c_book/chapter2/keywords_and_identifiers.html