标签:div str static int mod 问题: 动态 class name
<span style="font-size:18px;">char str1[] = "abc"; char str2[] = "abc"; const char str3[] = "abc"; const char str4[] = "abc"; const char *str5 = "abc"; const char *str6 = "abc"; char *str7 = "abc"; char *str8 = "abc"; cout << ( str1 == str2 ) << endl; cout << ( str3 == str4 ) << endl; cout << ( str5 == str6 ) << endl; cout << ( str7 == str8 ) << endl;</span>
而str5,str6,str7,str8是指针,它们指向同样的常量区域。
#include <stdio.h> char *returnStr() { char *p="hello world!"; return p; } int main() { char *str=NULL;//一定要初始化,好习惯 str=returnStr(); printf("%s\n", str); return 0; }
#include <stdio.h> char *returnStr() { char p[]="hello world!"; return p; } int main() { char *str=NULL;//一定要初始化,好习惯 str=returnStr(); printf("%s\n", str); return 0; }"hello world!"是一个字符串常量,存放在静态数据区,没错。
例如以下:
#include <stdio.h> char *returnStr() { static char p[]="hello world!"; //存放在静态存储区 return p; } int main() { char *str=NULL; str=returnStr(); printf("%s\n", str); return 0; }
标签:div str static int mod 问题: 动态 class name
原文地址:http://www.cnblogs.com/gavanwanggw/p/7246880.html