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 ;
}

Linux C/C++基础——二级指针做形参的更多相关文章

  1. go语言基础之指针做函数参数用地址传递

    1.指针做函数参数 示例: package main //必须有个main包 import "fmt" func swap(p1, p2 *int) { *p1, *p2 = *p ...

  2. go语言基础之指针做函数参数

    1.指针做函数参数 示例: package main //必须有个main包 import "fmt" func swap(a, b int) { a, b = b, a fmt. ...

  3. 【C语言】二维指针做形参

    转自:http://hi.baidu.com/gpmzccqceabimqq/item/f499f057aa1520404eff208b 关键: 传入时强制类型转换 + 使用时自己手工寻址 今天写程序 ...

  4. Linux C 程序 指针数组和二级指针(TEN)

    指针数组和二级指针 #include<stdio.h> int main(){ ] = {,,,,}; ], i; int **pp = p; //使p指针数组指向每一个a ; i < ...

  5. Linux运维基础采集项

    1. Linux运维基础采集项 做运维,不怕出问题,怕的是出了问题,抓不到现场,两眼摸黑.所以,依靠强大的监控系统,收集尽可能多的指标,意义重大.但哪些指标才是有意义的呢,本着从实践中来的思想,各位工 ...

  6. [c++] 二级指针的原理

    示例 将值(实参)传递给值(形参),无法更改val 1 #include <iostream> 2 using namespace std; 3 4 void change(int mem ...

  7. go语言基础之数组指针做函数参数

    1.数组指针做函数参数 示例: package main //必须有个main包 import "fmt" //p指向实现数组a,它是指向数组,它是数组指针 //*p代表指针所指向 ...

  8. linux c二级指针的内存分配和使用

    #include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h> ...

  9. 嵌入式-C语言基础:二级指针

    二级指针:可以理解为指向指针的指针,存放的是指针变量的地址. 下面用一级指针来保存一个指针变量的地址: #include<stdio.h> int main() { int *p1; in ...

随机推荐

  1. Python字符串拼接的五种方式

    第一种 通过加号(+)的形式 print('第一种方式通过加号形式连接 :' + 'love'+'Python' + '\n') 第二种 通过逗号(,)的形式 print('第二种方式通过逗号形式连接 ...

  2. ElementUI datepicker日期选择器时间选择范围限制

    ElementUI是饿了么推出的一套基于vue2.x的一个ui框架.官方文档也很详细,这里做一个element-ui日期插件的补充. 最近做项目用到了datepicker,需要对日期选择做一些限制, ...

  3. 怎么理解vue中$listeners属性?

    首先,$listeners是什么? 假设有父组件Parent和子组件Child // Parent <template> ... <child v-on:event-one=&quo ...

  4. React组件(组件属性this.state和this.props,css样式修饰组件)

    目录: 1.创建组件的第一种方式 function2.将组件抽离为单独的jsx文件3.省略.jsx后缀, 配置webpack设置根目录4.创建组件的第二种方式--使用class关键字创建组件5.组件私 ...

  5. npm安装cnpm时候报错code EINTEGRITY

    npm安装cnpm时候报错code EINTEGRITY错误展示 PS C:\Users\by\Desktop\element_ui_demo> npm install --g  npmnpm ...

  6. dstat命令 来自: http://man.linuxde.net/dstat

    来自: http://man.linuxde.net/dstat

  7. PTA 阶乘之和取模

    阶乘之和取模 (25 分) 输入正整数n, 计算S = 1!+2!+...+n!的末6位(不含前导0). 这里1<=n<=10​9​​. 输入样例: 例如输入: 20 输出样例: 输出: ...

  8. centos6升级系统内核

    1.升级系统内核查看内核版本: uname -r 2.6.32-573.8.1.el6.x86_64 导入elrepo的key: rpm --import https://www.elrepo.org ...

  9. python3笔记二十四:Mysql数据库操作命令

    一:学习内容 Mysql操作命令:启动服务.停止服务.连接数据库.退出数据库.查看版本.显示当前时间.远程连接 数据库操作命令:创建数据库.删除数据库.切换数据库.查看当前选择的数据库 表操作命令:查 ...

  10. php phpexcel 创建excel

    public function createExcel($result=[],$fileName=''){ \think\Loader::import('extend.excel.PHPExcel', ...