标签:style blog color os io ar div log
相同的字符串常量是共享的,而且是不可写的。
1 #include <iostream> 2 using namespace std; 3 4 char *string1, *string2; 5 6 int main() { 7 string1 = "abcd"; string2 = "abcd"; 8 if(string1 == string2) printf("strings are shared!\n"); 9 else printf("strings are NOT shared!\n"); 10 //有可能运行时错误 11 //string1[0] = ‘1‘; 12 if(*string1 == ‘1‘) printf("string are writable!\n"); 13 else printf("string are NOT writable!\n"); 14 15 return 0; 16 }
输出:
$ ./a.exe strings are shared! string are NOT writable!
标签:style blog color os io ar div log
原文地址:http://www.cnblogs.com/dracohan/p/3920464.html