20120519

variable name

Use simple, descriptive variable names.

. The first BASIC interpreter limited variables to a single letter and an optional digit ( A , B2 , C3 , etc.)

FORTRAN gave the programmer six characters to play with--really 5 1/2, since the first character denoted the default type.

In C the length of a variable name is unlimited (although the first 31 characters must be unique). So variable names like these:

disk_name total_count last_entry

http://www.oualline.com/style/c03.html

-----------------------------------------------

A variable is an entity whose value keeps on changing throughout the program execution. As we all know, data is stored in the memory of the computer. Actually, data is not stored in the variable. A variable is the name given to the memory location. A variable name is an entity that points to a particular memory location.
Variable can be of different types.

Rules for constructing variable names
1) A Variable name consists of any combination of alphabets, digits and underscores. Some compiler allows variable names whole length could be up to 247 characters. Still it would be safer to stick to the rule of 31 characters. Please avoid creating long variable name as it adds to your typing effort.
2) The first character of the variable name must either be alphabet or underscore. It should not start with the digit.
3) No commas and blanks are allowed in the variable name.
4) No special symbols other than underscore are allowed in the variable name.

-----------------------------------------------------------------

转义字符的完整诠释
转义字符是C语言中表示字符的一种特殊形式。通常使用转义字符表示ASCII码字符集中不可打印的控制字符和特定功能的字符,如用于表示字符常量的单撇号( '),用于表示字符串常量的双撇号( ")和反斜杠( \)等。转义字符用反斜杠\后面跟一个字符或一个八进制或十六进制数表示。

转义字符 意义 ASCII码值(十进制)
\a 响铃(BEL) 007
\b 退格(BS) 008
\f 换页(FF) 012
\n 换行(LF) 010
\r 回车(CR) 013
\t 水平制表(HT) 009
\v 垂直制表(VT) 011
\\ 反斜杠 092
\? 问号字符 063
\' 单引号字符 039
\" 双引号字符 034
\0 空字符(NULL) 000
\ddd 任意字符 三位八进制
\xhh 任意字符 二位十六进制


字符常量中使用单引号和反斜杠以及字符常量中使用双引号和反斜杠时,都必须使用转义字符表示,即在这些字符前加上反斜杠。
在C程序中使用转义字符\ d d d或者\ x h h可以方便灵活地表示任意字符。\ d d d为斜杠后面跟三位八进制数,该三位八进制数的值即为对应的八进制A S C I I码值。\ x后面跟两位十六进制数,该两位十六进制数为对应字符的十六进制A S C I I码值。

使用转义字符时需要注意以下问题:
1) 转义字符中只能使用小写字母,每个转义字符只能看作一个字符。
2) \v 垂直制表和\f 换页符对屏幕没有任何影响,但会影响打印机执行响应操作。
3) 在C程序中,使用不可打印字符时,通常用转义字符表示


注:
1,\v垂直制表和\f换页符对屏幕没有任何影响,但会影响打印机执行响应操作。
2,\n其实应该叫回车换行。换行只是换一行,不改变光标的横坐标;回车只是回到行首,不改变光标的纵坐标。
3,\t 光标向前移动四格或八格,可以在编译器里设置
4,\' 在字符里(即单引号里)使用。在字符串里(即双引号里)不需要,只要用 ' 即可。
5,\? 其实不必要。只要用 ? 就可以了(在windows VC6 和tc2 中验证)

转义字符是一种特殊的字符常量。转义字符以反斜线"\"开头,后跟一个或几个字符。转义字符具有特定的含义,不同于字符原有的意义,故称“转义”字符。例如,在前面各例题printf函数的格式串中用到的“\n”就是一个转义字符,其意义是“回车换行”。转义字符主要用来表示那些用一般字符不便于表示的控制代码。
常用的转义字符及其含义
转义字符  转义字符的意义

广义地讲,C语言字符集中的任何一个字符均可用转义字符来表示。表2.2中的\ddd和\xhh正是为此而提出的。ddd和hh分别为八进制和十六进制的ASCII代码。如\101表示字?quot;A" ,\102表示字母"B",\134表示反斜线,\XOA表示换行等。转义字符的使用
void main()
{
int a,b,c;
a=5; b=6; c=7;
printf("%d\n\t%d %d\n %d %d\t\b%d\n",a,b,c,a,b,c);
}
此程序练习转义字符的使用
a、b、c为整数 5->a,6->b,7->c
调用printf显示程序运行结果
printf("%d\n\t%d %d\n %d %d\t\b%d\n",a,b,c,a,b,c);
程序在第一列输出a值5之后就是“\n”,故回车换行;接着又是“\t”,于是跳到下一制表位置(设制表位置间隔为8),再输出b值6;空二格再输出c 值7后又是"\n",因此再回车换行;再空二格之后又输出a值5;再空三格又输出b的值6;再次后"\t"跳到下一制表位置(与上一行的6 对齐),但下一转义字符“\b”又使退回一格,故紧挨着6再输出c值7。

http://bbs.bccn.net/thread-195964-1-1.html

------------------------------------------------------------

Most compilers are divided into parts: the compiler front-end is called a lexical analyzer or a scanner. This part of the compiler reads the actual characters and creates tokens. It has a state machine which decides, upon seeing an escape character, whether it is genuine (for example when it appears inside a string) or it modifies the next character. The token is output accordingly as the escape character or some other token (such as a tab or a newline) to the next part of the compiler (the parser). The state machine can group several characters into a token.


It generally escapes the following character:

    In a string literal or character literal, it means escape the next character. \a means 'alert' (flashing the terminal, beeping or whatever), \n means 'linefeed', \xNUM means an hexadecimal number for example.
    If it appears as the last visible character before a newline, whether within a string or not (and even within a line-wide comment!), it acts as a line-continuation: The following newline character is ignored, and the next line is merged with the current line.

猜你喜欢

转载自wwwjjq.iteye.com/blog/1537302