本章问题
1.Comments in C do not nest(嵌套).What would be the result of "commenting out" the code in the example shown below?
(注释在C里面不能嵌套,下面“commenting out”注释的代码会产生什么结果?)
void squares( int limit ) { /* Comment out this entire function int i; /*loop counter*/ /* ** Print table of squares */ for( i = 0; i < limit; i += 1) printf("%d %d0, i, i * i“); End of commented-out code*/ }
answer : The outside(外侧的) comment ends at the end of the first enclosed(围绕的) comment. This make the variable i undefined in the rest of the function; the phrase End of comment-out code will be a syntax(句法) error,and the final closing */ will be illegal(非法的).
(外侧和围绕第一行的代码会使剩余函数没有定义i变量,最后一行”end of commented-out code将会出现句法错误,最后一个*/是非法的“)
2.What are the advantages of putting a large program into a single source file?What are the disadvantages?
(把一个大程序放在一个源文件中有什么优点?有什么缺点?)
answer :
Advantages:
a.When you want to modify a funcion,it is easy to determine(确定) which file it is in.
(当你要修改一个函数时,很容易确定它在文件的哪个文件)
b.You can safely user longer function names.Depending on the limits of your particular system,internal(内部) must be distinct from one another somewhere in the first 31 characters or more,whereas external names must be distinct from one another in the first six characters.
(你可以安全的使用长的函数名,取决于你的系统限制,前31个字符的内部名字必须不同,前六个字符的外部名字必须不同)
Disadvantages:
a.Depending on how powerful your editor is,it may be harder to locate(找出) a particular piece of code in large file than a small one.
(取决于你的编辑器,相比于一个小文件来说可能更难找出一个特殊的代码段)
b.Depending on your operating system,the type of editor you are using,and the size of the file,it may be more time consuming(消耗) to edit a large file than a small one.
(取决于你的操作系统和你所使用的编辑器的类型和文件的大小,相比于一个小文件可能需要花费更多的时间)
c.If you make a mistake in your editor,it is easy to lose the whole program.
(如果你在编辑器里犯了一个错误,可能更容易导致整个程序丢失)
d.Even if you change only one function,the entire program must be recompiled,which takes longer than recompiling only the modified function.
(即使你只是更改一个函数,整个程序都需要重新编译,这比只需要编译一个函数的时间要长)
e.It is harder to reuse general purpose functions from the program if they are buried in(埋在) with all the code that is specific(特别的) to that problem.
(会使得重用一个解决特殊问题的函数更难,因为这个函数跟所有的代码放在一起)
3.Show the string literal(逐字) that you would use with printf in order to print the following text,including the quotation(引用) marks.
(使用printf逐字打印出下列文本,包括双引号)
”Blunder??!??“
answer :
printf(""Blunder??!??"");
4.What is the value of 40? of 100? of x40? of x100? of 123? of x0123?
(40的值是多少?、100 、x40、x100、 123、x0123的值分别是多少?)
answer : The character equivalences(相等) given assume that the implementation(实行) users ASCII.
(假定用户实行的是ASCII码,则给定字符与ASCII码对应相等)
40 (Oct) = 32(Dec) = the space character(空格)
100 (Oct) = 64(Dec) = '@'
x40 (Hex) = 64(Dec) = '@'
x100 (Hex)is twelve bits (thouge the first three are zeros). On most machines this number is too big to be stored in a character , so the result is implementation dependent.
(x100 占据十二位,尽管前三位为0,在绝大多数机器上,这个值过大,无法存储在一个字符内,所以它的结果要依赖于编译器)