Chinaunix首页 | 论坛 | 博客
  • 博客访问: 420773
  • 博文数量: 77
  • 博客积分: 2948
  • 博客等级: 少校
  • 技术积分: 912
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-16 15:34
文章分类

全部博文(77)

文章存档

2014年(9)

2013年(9)

2011年(26)

2010年(33)

分类: C/C++

2014-01-08 13:02:26



  1. void *GetMemory(char **p)
  2. {
  3.     if(p == NULL)
  4.         printf("p = NULL\n");
  5.     *p = (char *)malloc(100);

  6.     printf("p = %p\n",*p);

  7.     return *p;
  8. }
  9. void main(void)
  10. {
  11.     char *str = NULL;
  12.     char *t = GetMemory(&str);
  13.     
  14.     printf("t = %p\n",t);
  15.     printf("str = %p\n",str);

  16.     strcpy(str, "hello world");
  17.     printf("%s\n",str);
  18. }
    将指针作为参数传递的时候,可以在函数里面更改指针里的内容,但是这个指针的内存地址不能被更改,如果要实现更改指针地址,必须传递指向指针的指针作为参数。
阅读(547) | 评论(0) | 转发(0) |
0

上一篇:人体时钟hone hone clock

下一篇:开源ftp

给主人留下些什么吧!~~