



    
     [1]
    
     符号标出的习题在网站
    
     https://exl.ptpress.cn:8442/ex/l/609033ea
    
    上有答案。以后各章也使用这一约定。
    符号标出的习题在网站
    
     https://exl.ptpress.cn:8442/ex/l/609033ea
    
    上有答案。以后各章也使用这一约定。
   
2.1节
1. 建立并运行由Kernighan和Ritchie编写的著名的“hello, world”程序:
#include <stdio.h>
int main(void)
{
  printf("hello, world\n");
}在编译时是否有警告信息?如果有,需要如何修改呢?
2.2节
     2. 思考下面的程序:
    2. 思考下面的程序:
   
#include <stdio.h>
int main(void)
{
  printf("Parkinson's Law:\nWork expands so as to ");
  printf("fill the time\n");
  printf("available for its completion.\n");
  return 0;
}(a) 请指出程序中的指令和语句。
(b) 程序的输出是什么?
2.4节
     3. 通过下列方法缩写程序dweight.c:(1) 用初始化器替换对变量
    3. 通过下列方法缩写程序dweight.c:(1) 用初始化器替换对变量
    
     height
    
    、
    
     length
    
    和
    
     width
    
    的赋值;(2) 去掉变量
    
     weight
    
    ,在最后的
    
     printf
    
    语句中计算
    
     (volume + 165)/ 166
    
    。
   
     4. 编写一个程序来声明几个
    4. 编写一个程序来声明几个
    
     int
    
    型和
    
     float
    
    型变量,不对这些变量进行初始化,然后显示它们的值。这些值是否有规律?(通常情况下没有。)
   
2.7节
     5. 下列C语言标识符中,哪些是不合法的?
    5. 下列C语言标识符中,哪些是不合法的?
   
    (a)
    
     100_bottles
    
   
    (b)
    
     _100_bottles
    
   
    (c)
    
     one__hundred__bottles
    
   
    (d)
    
     bottles_by_the_hundred_
    
   
    6. 为什么说在标识符中使用多个相邻的下划线(如
    
     current___balance
    
    )不太合适?
   
7. 下列哪些是C语言的关键字?
    (a)
    
     for
    
   
    (b)
    
     If
    
   
    (c)
    
     main
    
   
    (d)
    
     printf
    
   
    (e)
    
     while
    
   
2.8节
     8. 下面的语句中有多少个记号?
    8. 下面的语句中有多少个记号?
   
answer=(3*q–p*p)/3;9. 在练习题8的记号之间插入空格,使该语句更易于阅读。
10. 在dweight.c程序(➤2.4节)中,哪些空格是必不可少的?