L
liujiaping
I'm confused about the program below:
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";
//str6[0] = 'd'; // of coz error
char* str7 = "abc";
//str7[0] = 'd'; // error too
cout << boolalpha << (str1 == str2) << endl; // false
cout << boolalpha << (str3 == str4) << endl; // false
cout << boolalpha << (str5 == str6) << endl; // true
cout << boolalpha << (str6 == str7) << endl; // true
return 0;
}
I know there are differences between "char*" and "char[]", but I dont
know why. And since *str7 cannot be changed, does this mean that
"char*" is equvalent to "const char*"?
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";
//str6[0] = 'd'; // of coz error
char* str7 = "abc";
//str7[0] = 'd'; // error too
cout << boolalpha << (str1 == str2) << endl; // false
cout << boolalpha << (str3 == str4) << endl; // false
cout << boolalpha << (str5 == str6) << endl; // true
cout << boolalpha << (str6 == str7) << endl; // true
return 0;
}
I know there are differences between "char*" and "char[]", but I dont
know why. And since *str7 cannot be changed, does this mean that
"char*" is equvalent to "const char*"?