1.二级指针做形参

  #include<stdio.h>
#include<stdlib.h> void fun(int **temp)
{
*temp=(int*)malloc(sizeof(int));
**temp=; //可以,但是变量前两个*不常见,常用下面这种
//int *p=(int *)malloc(sizeof(int));
//*p=100;
//*temp=p;
}
int main()
{
int *p=NULL;
fun(&p);
printf("*p=%d\n",*p);
free(p);
p=NULL;
return ;
}

2.值传递1

#include <stdio.h>
#include <stdlib.h> void fun(int *tmp)
{
tmp = (int *)malloc(sizeof(int));
*tmp = ;
} int main(int argc, char *argv[])
{
int *p = NULL;
fun(p); //值传递,形参修改不会影响实参
printf("*p = %d\n", *p);//err,操作空指针指向的内存 return ;
}

值传递2

   #include <stdio.h>
#include <stdlib.h> void fun(int *tmp)
{
*tmp = ;
}
int main(int argc, char *argv[])
{
int *p = NULL;
p=(int *)malloc(sizeof(int));
fun(p); //值传递,形参修改不会影响实参
printf("*p = %d\n", *p);
free(p);
p=NULL;
return ;
}

返回堆区地址

#include <stdio.h>
#include <stdlib.h> int *fun()
{
int *tmp = NULL;
tmp = (int *)malloc(sizeof(int));
*tmp = ;
return tmp;//返回堆区地址,函数调用完毕,不释放
} int main(int argc, char *argv[])
{
int *p = NULL;
p = fun();
printf("*p = %d\n", *p);//ok //堆区空间,使用完毕,手动释放
if (p != NULL)
{
free(p);
p = NULL;
} return ;
}

最新文章

  1. HTML5 之拖放(drag与drop)
  2. Objective-C精选字符串处理方法
  3. 【转】单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构
  4. Storm集群安装部署步骤【详细版】
  5. SQLserver删除某数据库中所有表 方法 二
  6. 注册、卸载DLL
  7. 使用React、Node.js、MongoDB、Socket.IO开发一个角色投票应用的学习过程(三)
  8. Try out the latest C++ compiler toolset without waiting for the next update of Visual Studio
  9. javascript-几个基础的排序算法
  10. 深度优先搜索算法(DFS)以及leetCode的subsets II
  11. oracle 之 内存—鞭辟近里(一)
  12. String的Split方法的用法与要注意事项
  13. MySQL5.7关于密码二三事
  14. 去中心化存储项目终极指南 | Filecoin, Storj 和 PPIO 项目异同
  15. 【Nodejs】Nodejsの環境構築
  16. SSM框架报错分析(一)——There is no getter for property named &#39;XXX&#39; in &#39;class java.lang.String&#39;
  17. mysql only_full_group_by报错的问题(转)
  18. altera FIFO知识点
  19. CodeAction_beta02 斐波那契 (多维DP)
  20. 【Cesium】坐标理解(转)

热门文章

  1. Ubuntu16.04连接SSH出现 Server responded “Algorithm negotiation failed” 的解决方法
  2. Java开发工具汇总
  3. 【转】java中的clone
  4. win.10 禁止自动更新
  5. Python 特点
  6. Struts增删改查
  7. ga
  8. codevs 3022 西天收费站 x
  9. jquery文章链接
  10. 美团小程序框架mpvue入门教程