zoukankan      html  css  js  c++  java
  • 第 12 章 存储类别、链接和内存管理(存储类别)

     1 /*----------------------------
     2     parta.c -- 不同的存储类别
     3 ----------------------------*/
     4 
     5 #include <stdio.h>
     6 
     7 void report_count();
     8 void accumulate(int k);
     9 
    10 int count = 0;        //文件作用于,外部链接
    11 
    12 int main()
    13 {
    14     int value;        //自动变量
    15     register int i;    //寄存器变量
    16 
    17     printf("Enter a positive integer (0 to quit): ");
    18 
    19     while (scanf("%d", &value) == 1 && value > 0)
    20     {
    21         ++count;    //使用文件作用域变量
    22 
    23         for (i = value; i >= 0; --i)
    24             accumulate(i);
    25 
    26         printf("Enter a positive integer (0 to quit): ");
    27     }
    28 
    29     report_count();
    30 
    31     return 0;
    32 }
    33 
    34 void report_count()
    35 {
    36     printf("Loop executed %d times
    ", count);
    37 }
    parta.c
     1 /*----------------------------
     2     partb.c -- 程序的其余部分
     3     与 parta.c 一起编译
     4 ----------------------------*/
     5 #include <stdio.h>
     6 
     7 extern int count;        //引用式声明,外部链接
     8 
     9 static int total = 0;    //静态定义,内部链接
    10 
    11 //void accumulate(int k);    //函数原型
    12 
    13 void accumulate(int k)            // k 具有块作用域,无连接
    14 {
    15     static int subtotal = 0;    //静态,无连接
    16 
    17     if (k <= 0)
    18     {
    19         printf("loop cycle: %d
    ", count);
    20         printf("subtotal: %d; total: %d
    ", subtotal, total);
    21         subtotal = 0;
    22     }
    23     else
    24     {
    25         subtotal += k;
    26         total += k;
    27     }
    28 }
    partb.c

  • 相关阅读:
    delphi参数传递
    Delphi OO
    Delphi Excel
    Delphi Register
    西安前端交流会
    web前端开发教程系列-4
    web前端开发教程系列-3
    web前端开发教程系列-2
    web前端开发教程系列-1
    露个脸
  • 原文地址:https://www.cnblogs.com/web1013/p/9139447.html
Copyright © 2011-2022 走看看