const char* str 与char str[10]

https://blog.csdn.net/sinat_34886122/article/details/82760638

基础,且重要

 

 

===================

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  char *p="hello";//是把字符串常量"hello"的首地址赋值给 p
  char c[10]="hello";//等价于 strcpy(c,"hello");
  c[0]='H';
  printf("c[0]=%c\n",c[0]);
  printf("p[0]=%c\n",p[0]);
 
  //p[0]='H';//不可以对常量区数据进行修改
  
  p="world";//将字符串 world 的地址赋值给 p
  //c="world";//非法:
/*
p 是一个指针变量,因此我们可以将字符串 world 的首地址重新赋值给 p,而数组名 c
本身存储的就是数组的首地址,是确定的,不可修改的,c 等价于符号常量,因此如果
c=”world”打开就会造成编译不通。 
*/
  return 0;
}

 ==========================

关于数组指针与二维数组,二级指针 ,在6月7日C语言第五章PDF上。

posted @ 2019-11-18 22:24  代号870  阅读(355)  评论(0编辑  收藏  举报