- 论坛徽章:
- 0
|
调试源码:
- ...
- const char *array = "whatever"; //array地址不变,所指向的内容可以变
- printf("Address:0x%x\n", &array);
- printf("Context:0x%x\n", array);
- array = "I love you"; //另外的常量的地址被赋值给array作为内容, 但不能单独赋值,*array++ = 'x'等。
- printf("Address:0x%x\n", &array);
- printf("Context:0x%x\n\n", array);
- const char *cp = "you love me";
- printf("Address:0x%x\n", &cp);
- printf("Context:0x%x\n", cp);
- cp = array;
- printf("Context:0x%x\n", cp);
- printf("%s\n", cp);
复制代码
调试结果:
- [root@root ANSI]# ./a.out
- Address:0xfeefb464
- Context:0x80485b0
- Address:0xfeefb464
- Context:0x80485d5
- Address:0xfeefb460
- Context:0x80485ef
- Context:0x80485d5
- I love you
复制代码 |
|