二级指针

来源:互联网 发布:知乎 日剧推荐 编辑:程序博客网 时间:2024/04/27 19:53
Code:
  1. #include<iostream>  
  2. using namespace std;  
  3.   
  4. char* Getmem(char *,int);  
  5. /* 
  6. void Getmem(char *&,int); 
  7.  
  8. void Getmem(char **,int); 
  9. */  
  10. int main()  
  11. {  
  12.     char *str=NULL;  
  13.     char *p;  
  14.     p=Getmem(p, 100);  
  15. //  Getmem(str,100);  
  16.     strcpy(str,"hello");  
  17.     cout<<str<<endl;  
  18.     return 0;  
  19. }  
  20.   
  21. char* Getmem(char *p,int num)  
  22. {  
  23.     char *q;  
  24.     q=new char[num];  
  25.     return q;  
  26. }  
  27.   
  28. /* 
  29. void Getmem(char **p,int num) 
  30. { 
  31.     *p=new char[num]; 
  32. } 
  33.  
  34. void Getmem(char *&p,int num) 
  35. { 
  36.     p=new char[num]; 
  37. } 
  38.  
  39.  */  
  40.   
  41. -------------------------------------------------  
  42.   
  43. #include<iostream>  
  44. using namespace std;  
  45. char* Getmem(int);  
  46. /* 
  47. void Getmem(char *&,int); 
  48.  
  49. void Getmem(char **,int); 
  50. */  
  51. int main()  
  52. {  
  53.     char *str=NULL;  
  54.     str=Getmem(100);  
  55. //  Getmem(str,100);  
  56.     strcpy(str,"hello");  
  57.     cout<<str<<endl;  
  58.     return 0;  
  59. }  
  60. char* Getmem(int num)  
  61. {  
  62.     char *q;  
  63.     q=new char[num];  
  64.     return q;  
  65. }