您的位置:首页 > 其它

字符串常量

2016-06-20 21:50 239 查看
用常量字符串去赋值给指针和初始化数组的时候是不一样的。

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
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{
cout<< static_cast<const void *>(str1)<<" "<<static_cast<const void *>(str2)<<endl;
printf("str1 and str2 are not same.\n");
}
if(str3 == str4){
cout<<static_cast<const void *>(str3)<<" "<<static_cast<const void *>(str4)<<endl;
printf("str3 and str4 are same.\n");
}else{
printf("str3 and str4 are not same.\n");
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: