指向字符串的指针 也可以指向常量 也可以指向储存字符串的数组

 1 //指向字符串的指针 也可以指向常量  也可以指向储存字符串的数组
 2 
 3 
 4 #include<stdio.h>
 5 #include<stdlib.h>
 6 #include<string.h>
 7 
 8 int main ()
 9 {
10     //2.
11    // printf("%p\n",*"你好,河南!"); //*取这个地址所对应的值
12 
13     //1.
14    // char * words = "My heart is still.";
15    // words += 9;
16    // puts(words);    // is still.
17 
18    //3.
19    //数组和指针
20    //初始化字符数组时会把静态存储区的字符串拷贝到数组中
21    //初始化指针时只把字符串的地址拷贝给指针
22 
23     char str1[] = "For The Horde";
24     char *str2 = "For The Horde";
25 
26     printf("字符串常量的地址:%p\n","For The Horde");
27     printf("字符数组的首地址:%p\n",str1);
28     printf("字符指针的取值: %p\n",str2);
29 
30 
31     //str1++;   不能执行   数字不能++
32     //str2++    可以执行   指针可以移动
33 
34 }

 

posted on 2021-07-28 08:59  Bytezero!  阅读(188)  评论(0编辑  收藏  举报