//
// 关于字符数字的比较
//
// [8/24/2015 wangjian-pc]
#include <iostream>
int main()
{
char str1[] = "hello world";
char str2[] = "hello world";
char *str3 = "hello world";
char *str4 = "hello world";
if (str1 == str2)
{
printf("str1 and str2 are same.\n");
}
else
{
printf("str1 and str2 are not same.\n");
}
if (str3 == str4)
{
printf("str3 and str4 are same.\n");
}
else
{
printf("str3 and str4 are not same.\n");
}
system("pause");
return 0;
}
// "hello world"本身就是一个地址,然后在栈区定义了四个指针都是指向同一个地址,
// 指针比较的时候比较的是指针存放的地址,而不是指针本身的地址
// 同时字符数组呢,是存在栈区,四个数组变量,每个变量比较的都是数组的首地址,四个不同的变量当然地址不一样。
// 输出 str1 and str2 are not same.
// str3 and str4 are same.
字符数组比较
最新推荐文章于 2024-02-18 19:11:31 发布