1.在C语言中,注释不允许嵌套。在下面的代码中,用注释来“注释掉”一段语句会导致什么结果?
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 comented-out code */
}
解析:
for语句之前的函数体的内容都被注释了,并且for语句结束后的部分是无效的语句。
#include <stdio.h>
#include <stdlib.h>
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 comented-out code */
}
输出:
2.把一个大型程序放入一个单一的源文件中有什么优点和缺点?
解析:
优点:所有的函数,变量名都能清晰的展示在当前源文件中。
缺点:大型程序的所有内容都要被编译,这会花费更的时间和空间;可能会意外地访问应该属于私有的函数或变量;这种方法让我们需要在数百行不相关的代码中寻找所需要的那组声明,