字符数组与字符串指针的区别
2017-03-17 15:12
211 查看
字符串指针与字符数组一般情况下都能对存储的字符串进行修改等操作,但是当字符串指针被定义为字符串常量时(静态区),字符串指针所指向的字符串就不能被改变。如下:
#include <stdio.h>
int main()
{
char s1[]="hello,world";
char s2[]="hello,world";
char *s3;
char *s4;
s3="hello,world";
s4="hello,world";
// s3=s1;
if(s1==s2)
printf("s1=s2\n");
else
printf("s1!=s2\n");
if(s3==s4)
printf("s3=s4\n");
else
printf("s3!=s4\n");
//*s3='e';//常亮不可赋值
s1[1]='e';
printf("%x\n",s1);
printf("%x\n",s2);
printf("%x\n",s3);
printf("%x\n",s4);
}
#include <stdio.h>
int main()
{
char s1[]="hello,world";
char s2[]="hello,world";
char *s3;
char *s4;
s3="hello,world";
s4="hello,world";
// s3=s1;
if(s1==s2)
printf("s1=s2\n");
else
printf("s1!=s2\n");
if(s3==s4)
printf("s3=s4\n");
else
printf("s3!=s4\n");
//*s3='e';//常亮不可赋值
s1[1]='e';
printf("%x\n",s1);
printf("%x\n",s2);
printf("%x\n",s3);
printf("%x\n",s4);
}
输出:
s1!=s2 s3=s4 90613340 90613330 4006d8 4006d8
相关文章推荐
- 函数内 声明一个字符数组和一个指向字符串数组的指针 区别
- 字符串指针与字符数组的区别
- 字符串指针与字符数组的区别
- C语言字符串指针变量与字符数组的区别
- 字符串指针与字符数组的区别(一)--字符串常量的值不能改
- 字符数组名与字符串指针变量名的区别(转)
- 字符数组名与字符串指针变量名的区别
- c语言指针字符串与字符数组字符串的区别
- 字符串指针与字符数组的区别
- 字符串指针与字符数组的区别
- 字符串string 字符数组与指向字符串的指针pchar的区别与联系
- 字符串指针与字符数组的区别
- 字符串指针与字符数组的区别
- 字符串指针与字符数组的区别
- 字符串指针与字符数组的区别
- 字符串指针与字符数组的区别
- 关于数组与指针的应用及区别-针对字符串去左边多余的‘0’字符
- 字符串指针与字符数组的区别
- 字符数组和字符串指针区别
- 字符串指针与字符数组的区别