#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "abc";
cout << boolalpha << ( str1==str2 ) << endl; // 输出什么?
cout << boolalpha << ( str3==str4 ) << endl; // 输出什么?
cout << boolalpha << ( str5==str6 ) << endl; // 输出什么?
return 0;
}
// out put:
0
using namespace std;
int main(int argc, char *argv[])
{
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "abc";
cout << boolalpha << ( str1==str2 ) << endl; // 输出什么?
cout << boolalpha << ( str3==str4 ) << endl; // 输出什么?
cout << boolalpha << ( str5==str6 ) << endl; // 输出什么?
return 0;
}
// out put:
0
0
1
str1 0x0012ff60 "abc" char [4]
str2 0x0012ff54 "abc" char [4]
str3 0x0012ff48 "abc" const char [4]
str4 0x0012ff3c "abc" const char [4]
str5 0x00415800 "abc" const char *
str6 0x00415800 "abc" const char *
字符数组用变量名引用是代表首地址(而argc是整形, 其引用就是其值):
str1-->0x0012ff60
str1,str2,str3,str4都分配在栈上. str5,str6分配在静态数据区(进程空间内)
str1,str2,str3,str4和str5,str6的地址差别很大
1. 字符数组的引用.
2. 变量的空间分配
str1 0x0012ff60 "abc" char [4]
str2 0x0012ff54 "abc" char [4]
str3 0x0012ff48 "abc" const char [4]
str4 0x0012ff3c "abc" const char [4]
str5 0x00415800 "abc" const char *
str6 0x00415800 "abc" const char *
字符数组用变量名引用是代表首地址(而argc是整形, 其引用就是其值):
str1-->0x0012ff60
str1,str2,str3,str4都分配在栈上. str5,str6分配在静态数据区(进程空间内)
str1,str2,str3,str4和str5,str6的地址差别很大
1. 字符数组的引用.
2. 变量的空间分配