【C语言】【unix c】同名局部变量之间关系
2017-08-17 23:04
453 查看
代码: #include <stdio.h> #include <sys/types.h> #include <unistd.h> int j; void count(void) { static int i = 1; printf("++i1 = %d\n", ++i); printf("i1 address:%p\n", &i); return; } void count1(void) { static int i; printf("++i2 = %d\n", ++i); printf("i2 address:%p\n", &i); return; } int main(void) { int i; for(i = 0; i < 5; i++) { count(); count1(); } printf("j address is:%p\n", &j); getchar(); return 0; } 命令: tarena@ubuntu:~/day/day26$ ./a.out 结果: pid:4237 ++i1 = 2 i1 address:0x804a01c ++i2 = 1 i2 address:0x804a028 ++i1 = 3 i1 address:0x804a01c ++i2 = 2 i2 address:0x804a028 ++i1 = 4 i1 address:0x804a01c ++i2 = 3 i2 address:0x804a028 ++i1 = 5 i1 address:0x804a01c ++i2 = 4 i2 address:0x804a028 ++i1 = 6 i1 address:0x804a01c ++i2 = 5 i2 address:0x804a028 j address is:0x804a02c 测试编译连接后的状态信息: 命令: tarena@ubuntu:~/day/day26$ nm a.out 结果: 08049f28 d _DYNAMIC 08049ff4 d _GLOBAL_OFFSET_TABLE_ 0804868c R _IO_stdin_used w _Jv_RegisterClasses 08049f18 d __CTOR_END__ 08049f14 d __CTOR_LIST__ 08049f20 D __DTOR_END__ 08049f1c d __DTOR_LIST__ 08048800 r __FRAME_END__ 08049f24 d __JCR_END__ 08049f24 d __JCR_LIST__ 0804a020 A __bss_start 0804a014 D __data_start 08048640 t __do_global_ctors_aux 080483c0 t __do_global_dtors_aux 0804a018 D __dso_handle w __gmon_start__ 08048632 T __i686.get_pc_thunk.bx 08049f14 d __init_array_end 08049f14 d __init_array_start 08048630 T __libc_csu_fini 080485c0 T __libc_csu_init U __libc_start_main@@GLIBC_2.0 0804a020 A _edata 0804a030 A _end 0804866c T _fini 08048688 R _fp_hw 080482f8 T _init 08048390 T _start 0804a020 b completed.7108 08048444 T count 08048485 T count1 0804a014 W data_start 0804a024 b dtor_idx.7110 08048420 t frame_dummy U getchar@@GLIBC_2.0 U getpid@@GLIBC_2.0 0804a01c d i.2461 //在程序中两个函数的变量名是一样的,但是为了区分,在编译后局部变量的后面会有一个编号 0804a028 b i.2470 // 变量名前面的d表示已初始化的数据段,b是未初始化的局部变量,也在数据段 0804a02c B j //变量前面大写字母表示全局变量,小写的代表局部变量 080484c6 T main U printf@@GLIBC_2.0
相关文章推荐
- 关于C语言中 int型变量和unsigned int变量范围之间的关系
- 作用域、链接属性、存储类型示例——文件之间变量、函数的关系
- JAVA开发人员学习C++之变量名和变量地址之间是什么关系
- python变量、引用、拷贝之间的关系
- 变量指针和地址之间的关系
- UNIX和Linux之间有什么关系?
- C语言中全局变量和局部变量同名时的访问方法
- 局部变量与成员变量的同名问题&显示初始化
- C语言之函数返回局部变量
- arguments实参集合与局部变量、参数关系
- C语言的那些秘密之--函数返回局部变量
- 浅析c语言中的变量(局部变量,外部变量,静态变量,寄存器变量)
- Linux与Unix之间的关系以及Linux的发展
- C语言在函数名与函数体之间定义变量--K&r C和ANSI C两种风格的函数声明和定义
- C语言中scanf函数与输入缓冲区之间的关系
- 【C语言】-变量之间的类型转换
- 超级简单的例子说明JAVA PACKET CLASS 和变量之间的关系
- java变量类型之间的转换关系
- C语言内存模型与指针以及变量的关系
- 变量指针和地址之间的关系