9.字符串-三种字符串的表示方法
#include <stdio.h> #include <string.h> #define MSG "woshishuya" int main() { char arr_str[] = MSG; char * pt_str = MSG; printf("1.数组的pointer:%p\n", arr_str); printf("2.pointer的pointer:%p\n", pt_str); printf("3.字符串的pointer:%p\n", pt_str); /* 执行结果: 数组的pointer:0x7ffee8fa8abd pointer的pointer:0x106c57f5c 字符串的pointer:0x106c57f5c 字符串属于静态常量存储在静态存储区(static memory) 1."string" 他本身就是字符串对象的指针(首个字节的地址) 2.指针变量指向字符串时,是把字符串对象的指针复制给指针变量 3.字符数组存储字符串时,会把静态存储内的字符串复制给字符数组(在内存中存储两份) */ return 0; }