2018年3月10日
摘要: char *strA() { char str[] = "hello word"; return str; } 上述程序有什么问题? 简单的来说,str是个局部变量的地址,作为返回值,有可能被提前回收。 那么局部变量可以作为函数的返回值吗,这个问题不能一概而论。局部变量作为返回值时,一般是系统先申请 阅读全文
posted @ 2018-03-10 23:01 Mini_Coconut 阅读(2473) 评论(0) 推荐(0) 编辑
摘要: 字符串的sizeof和strlen 考虑下面的问题: char a[] = "abcdef"; char b[20] = "abcdef"; string s = "abcdef"; cout<<strlen(a)<<endl; // 6,字符串长度 cout<<sizeof(a)<<endl; / 阅读全文
posted @ 2018-03-10 21:00 Mini_Coconut 阅读(637) 评论(1) 推荐(0) 编辑