Chinaunix首页 | 论坛 | 博客
  • 博客访问: 103461
  • 博文数量: 102
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1011
  • 用 户 组: 普通用户
  • 注册时间: 2014-01-15 13:58
个人简介

普普通通一个人

文章分类

全部博文(102)

文章存档

2018年(1)

2015年(13)

2014年(88)

我的朋友

分类: C/C++

2014-01-22 16:13:42


点击(此处)折叠或打开

  1. #include<stdio.h>

  2. void fun_a(void);    /* function prototype */
  3. void fun_b(void);    /* function prototype */
  4. void fun_c(void);    /* function prototype */

  5. int x = 1;            /* globe variable */

  6. int main(){
  7.     int x = 5;    /* local variable to main */
  8.     printf("local x in outer scope of main is %d\n", x);

  9.     {    /* start new scope */
  10.         int x = 7;
  11.         printf("local x in inner scope of main is %d\n", x);
  12.     }    /* end new scope */

  13.     printf("local x in outer scope of main is %d\n", x);

  14.     fun_a();    /* fun_a has automatic local x */
  15.     fun_b();    /* fun_b has static local x */
  16.     fun_c();    /* fun_c use globe x */
  17.     fun_a();    /* fun_a reinitialize automatic local x */
  18.     fun_b();    /* static x retains its previous value */
  19.     fun_c();    /* globe x also retain its value */

  20.     printf("local x in main is %d\n", x);
  21.     return 0;
  22. }

  23. void fun_a(void){
  24.     int x = 25;    /* initialized each time a is called */
  25.     printf("\nlocal x in fun_a is %d after entering fun_a\n", x);
  26.     ++x;
  27.     printf("local x in fun_a is %d before exiting fun_a\n", x);
  28. }

  29. void fun_b(void){
  30.     static int x = 50; /* static initialization only */
  31.     printf("\nlocal static x is %d on entering fun_b\n", x);
  32.     ++x;
  33.     printf("local static x is %d on exiting fun_b\n", x);
  34. }

  35. void fun_c(void){
  36.     printf("\nglobe x is %d on entering fun_c\n", x);
  37.     x *= 10;
  38.     printf("globe x is %d on exiting fun_c\n", x);
  39. }

阅读(264) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~