int main()
{
	char buf[100];
	char *p=buf;
	//1、p指向buf的首元素
	//2、strcpy()给p所指向的内存拷贝内容,字符串拷贝给buf
	strcpy(p,"hello");

	printf("p=%s  buf=%s\n",p,buf);

	printf("s1=%s\n","hello mike");
	printf("s2=%p\n","hello mike");
	printf("s3=%s\n","hello mike"+1);
	printf("s4=%p\n","hello mike"+1);
	printf("s5=%c\n",*("hello mike"+1));


	//1、字符串常量就是此字符串的首元素地址
	printf("s1=%p\n","hello mike");
	char *p1="hello mike";
	printf("p1=%p\n",p1);
	char *p2="hello mike";
	printf("p2=%p\n",p1);

	//2、字符串常量,文字常量区的字符串,只读,不能修改
	printf("*p1=%c\n",*p1);//读 ,ok

	//3、p1指向字符串常量,字符串常量为只读,不能修改
	//*p1='a';//修改,err

	char *p3="hello";
	//strcpy(p3,"abc");//err

	return 0;
}

字符串常量初始化

    //p指针保存了“hello”的地址
	//指针指向的内容不能修改
	char *p="hello";

	//1、把“hello”一个一个字符放在buf数组中
	//2、数组的元素可以修改
	char buf[]="hello";

字符串常量初始化

相关文章:

  • 2021-09-25
  • 2021-07-06
  • 2021-09-05
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
猜你喜欢
  • 2019-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-07-07
  • 2022-02-22
相关资源
相似解决方案