首页 > 编程语言 > 详细

C/C++语言参数传递----函数/方法 参数的指针引用传递

时间:2015-12-20 13:09:58      阅读:187      评论:0      收藏:0      [点我收藏+]
int m_value = 1;
void func(int *p)
{
    p = &m_value;
}

int main(int argc, char *argv[])
{
    int n = 2;
    int *pn = &n;
    cout << *pn << endl;
    func(pn);
    cout << *pn <<endl;
    return 0;
}

看一下输出结果

2
2

-------其实上面这些例子,看一百次,我个人觉得,也看不出实际意义

 

#include <stdio.h>
#include <malloc.h>
#include <string.h>

void Allocate(char* p,int size){

printf("\n%x",&p);
printf("\n%x",p);

p=(char*)malloc(size);
}
void Free(char* p){
free(p);
}
void main()
{
char *str=NULL;
printf("\n%X",&str);
printf("\n%X",str);
Allocate(str,100);
strcpy(str,"Hello World!");
printf("\n%s",str);
Free(str);
printf("\nstr=%s",str);

}

------上面的这样的错误案例,才有实际的教学意义!!!

 

 

http://www.cnblogs.com/li-peng/p/4116349.html

http://blog.csdn.net/whzhaochao/article/details/12891329  ----经典,用事实说话

C/C++语言参数传递----函数/方法 参数的指针引用传递

原文:http://www.cnblogs.com/porter/p/5060559.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!