函数参数为 "char* p" 与 "char*& p" 的区别
2013-03-31 10:18
441 查看
#include <iostream> using namespace std; void New(char*& p) //注意:这里的参数不能用"char* p",而必须要用"char*& p"。 { p = new char[32]; } int main(int argc, char* argv[]) { char* p = NULL; New(p); strcpy(p, "hello"); //"strcpy"只会在有效值之后补个 '\0' ,并不会把所有旧值都清空。 printf("%s", p); return 0; }
相关文章推荐
- 函数参数为 "char* p" 与 "char*& p" 的区别
- C++的基础知识(十一)--数组做函数参数、数组名a与&a区别、数组名a的"数据类型"
- C语言中值得深入知识点----数组做函数参数、数组名a与&a区别、数组名a的"数据类型"
- error C2664: “int CWnd::GetWindowTextW(LPTSTR,int) const”: 不能将参数 1 从“char [10]”转"相关的问题
- char amessage[] = "the time";与char *pmessage = "the time";区别
- C#: 过程或函数""需要""参数,但未提供该参数
- 关于笔试题 "在函数里char p[] = "hello world" 与 char *p = "Hello world""
- 函数参数有&L,L的区别!
- C++ :函数中无需改变传入参数的值时,定义时把 “Item & x ” 都改成 \"const Item & x\"
- C++ * a和*&a作为函数的参数时有什么区别
- error: 函数调用缺少参数列表;请使用“&BinTree<char>::_PrintNode”创建指向成员的指针
- 主函数中的语句"char* pAddress=(char*)&a
- char *s="string"和char s[]="string"的区别
- error C2664:char *strcpy(char *,const char *)& 无法将参数 2 从CString"转换为const char *
- char *string="xxxxxxxxx" 与 char string[]="xxxxx"的区别
- char str[] = "hello world";和char *str = "hello world";区别
- char *p="Mayuyu"与char p[]="Mayuyu"的区别
- 面试题--字符串指针与字符串数组的区别char* st="abc;与char* str[]="abc";的异同
- char* a = "zhf"; 和 char a[] = "zhf"; 之间的区别
- open函数后面参数'a','w','r'的区别