变量作用域

时间:2015-12-02 20:41:02   收藏:0   阅读:254

变量作用域使用注意案例:

Demo:

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a = 20;
    int score = a + 100;
    printf("1--%d\n",score);//结果:120
    {
        int score = 50;//定义的这个score属于这个作用域的(这个个大括号)
        {
            score = 10;
            printf("2--%d\n",score);//结果:10
        }
        a = 10;//找所定义的a
    }
    {
        score = a + 250;
        printf("3--%d\n",score);//结果:260
        
        int score = 30;//定义的这个score属于这个作用域(大括号)
        printf("4--%d\n",score);//结果:30
    }
    printf("5--%d\n",score);//结果:260
    
    return 0;
}

 

原文:http://www.cnblogs.com/M-Y-P/p/5013981.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!