c语言程序块中初始化变量对同名变量作用域的影响

 

001、

复制代码
[root@PC1 test1]# ls
test1.c  test2.c
[root@PC1 test1]# cat test1.c
#include <stdio.h>

int main(void)
{
        int i;
        int x = 10000;
        for(i = 0; i < 4; i++)
        {
                int x = i * 5;
                printf("x = %d\n", x);
        }
        printf("x = %d\n", x);
        return 0;
}
[root@PC1 test1]# cat test2.c
#include <stdio.h>

int main(void)
{
        int i;
        int x = 10000;
        for(i = 0; i < 4; i++)
        {
                x = i * 5;
                printf("x = %d\n", x);
        }
        printf("x = %d\n", x);

        return 0;
}
[root@PC1 test1]# gcc test1.c -o kkk
[root@PC1 test1]# gcc test2.c -o mmm
[root@PC1 test1]# ls
kkk  mmm  test1.c  test2.c
[root@PC1 test1]# ./kkk
x = 0
x = 5
x = 10
x = 15
x = 10000
[root@PC1 test1]# ./mmm
x = 0
x = 5
x = 10
x = 15
x = 15
复制代码

 。

 

posted @   小鲨鱼2018  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-11-23 ggplot2 绘图 x轴标签顺序
2023-11-23 ggplot2 中绘图清空 x轴或者y轴的title
2023-11-23 ggplot2 中 绘图调整刻度线标签的长度
2023-11-23 R语言控制台一直出现 + 号该怎么处理
2020-11-23 linux 系统中个人用户主页功能
点击右上角即可分享
微信分享提示