c语言中块作用域的优先级高于文件作用域
001、
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c #include <stdio.h> int a = 100; // 该变量具有文件作用域 int main(void) { printf("a = %d\n", a); // 在程序快中调用外部变量 return 0; } [root@PC1 test]# gcc test.c -o kkk [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk a = 100
。
002、
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试程序 #include <stdio.h> int a = 100; int main(void) { int a = 500; // 块作用域的变量, 优先级高于文件作用域 printf("a = %d\n", a); return 0; } [root@PC1 test]# gcc test.c -o kkk ## 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## 运算测试 a = 500
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-11-22 ggplot 中绘图设置 轴标签与绘图区域的间距
2021-11-22 linux 系统中shell实现将fasta文件的碱基转换为一行及还原
2020-11-22 linux 系统中semanage命令
2020-11-22 linux系统中 SElinux安全子系统
2020-11-22 linux 系统中httpd服务的配置参数