博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
指针作为函数的出入参数例子说明
阅读量:4166 次
发布时间:2019-05-26

本文共 2135 字,大约阅读时间需要 7 分钟。

1 第一种: 参数是入参也是出参 函数里面的*pmon 是指针指向的值;

//得到指定月份的上一个月份;

void get_prev_month(INT32 *pYear, INT32 *pMon)

{

    if ( *pMon == 1 )

    {

        *pYear -= 1;

        *pMon = 12;

    }

    else

    {

        *pMon -= 1;

    }

}

2

//字符串转换成字符数组

//输入 src指针 ,输出 des指针,函数的作用是改变des指针指向的位置的值

void str2byte(CHAR *src, UINT8 *des, INT32 length) //jlb 如果输出参数是一个* ,则des[i]

{

    INT32 i;

    CHAR tmp[3];

    memset(tmp, 0, sizeof(tmp));

    for(i = 0; i < length; i++)

    {

        tmp[0] = src[i * 2];

        tmp[1] = src[i * 2 + 1];

        des[i] = strtol(tmp, NULL, 16);

    }

}

3

CHAR *write_buf=malloc(16);

// 输入 t_sys_time;输出 write_buf数组

encodeFramBuf(t_sys_time,&write_buf);

VOID encodeFramBuf(RTC_TIME sys_time,CHAR **writebuf)

//jlb 如果输出参数是两个* ,则(*writebuf)[0]

{

    (*writebuf)[0]=((sys_time.tm_year) / 100);

    (*writebuf)[1] = ((sys_time.tm_year ) % 100);

    (*writebuf)[2] = (sys_time.tm_mon );

    (*writebuf)[3] = (sys_time.tm_mday);

    (*writebuf)[4] = (sys_time.tm_hour);

    (*writebuf)[5] = (sys_time.tm_min);

    (*writebuf)[6] = (sys_time.tm_sec);

}

4

CHAR *write_buf=malloc(16);

// 输入 t_sys_time;输出 write_buf数组

encodeFramBuf(t_sys_time,write_buf);

VOID encodeFramBuf(RTC_TIME sys_time,CHAR *writebuf)

//jlb 如果输出参数是1个* ,则writebuf[0]

{

    writebuf[0]=((sys_time.tm_year) / 100);

    writebuf[1] = ((sys_time.tm_year ) % 100);

    writebuf[2] = (sys_time.tm_mon );

    writebuf[3] = (sys_time.tm_mday);

    writebuf[4] = (sys_time.tm_hour);

    writebuf[5] = (sys_time.tm_min);

    writebuf[6] = (sys_time.tm_sec);

}

5 重重之重的

    unsigned char * buff_p;

pyldLen=prime_recv(&remoteLLCAddr, &remoteSap, &srcSap,&buff_p);

//经过上面prime_recv函数之后,可以将buff_p的值打印出来,

for(i=0;i < pyldLen;i++) { printf("%02x ", buff_p [i]); }

 

int prime_recv(int * premoteLLCAddr, int * premoteSap, int * psrcSap, unsigned char**ppyldBuff_p)

{

int nRet = 0;

{

// get MAC Address by Serial Number

 

nRet = g_tVar.nRxBufLen;

*ppyldBuff_p = g_tVar.RxBuf;// g_tVar.RxBuf是ST封装的物理层读取的BUF,所以这里用指针最好。 ppyldBuff_p是二重指针,*ppyldBuff_p是减去一层指针

g_tVar.nRxBufLen = 0;

 

*premoteLLCAddr = g_tVar.RxSA;// premoteLLCAddr是一重指针,*premoteLLCAddr是取里面的内容 下面两个相同

*premoteSap = g_tVar.RxSSAP;

*psrcSap = g_tVar.RxDSAP;

}

return nRet;

}

6 备注:出参是一个*的

输出一个字节的话,比如例子5的:*premoteSap = g_tVar.RxSSAP;

输出多个字节的话:比如例子 4 的 writebuf[0]、writebuf[1]、。。。。。。。。

转载地址:http://rghxi.baihongyu.com/

你可能感兴趣的文章
【MongoDB】The basic operation of Mongodb, Insert\Query\Delete\Update
查看>>
【MongoDB】The high Query operation of MongoDB(一)
查看>>
【MongoDB】The high query operation of MongoDB(二)
查看>>
【MongoDB】The Regex Expression query of MongoDB
查看>>
软件开发模型【仅提供链接】
查看>>
【MongoDB】The high query operation of MongoDB(三)
查看>>
python中thread的setDaemon、join的用法
查看>>
【MonogoDB】The high update operation of MongoDB
查看>>
MySQL集群简介与配置详解
查看>>
MySQL数据库集群进行正确配置步骤
查看>>
mongodb数据导入导出以及备份恢复
查看>>
mongodb数据导入导出以及备份恢复(二)
查看>>
mongodb数据导入导出以及备份恢复(三)
查看>>
mongodb数据导入导出以及备份恢复
查看>>
python整理二十七——egg文件制作与安装【仅提供链接地址】
查看>>
十一新疆之旅中邂逅的一首诗《黄河,母亲之河》
查看>>
【MongoDB】The description of index(一)
查看>>
MongoDB索引学习笔记
查看>>
【MonogDB】The description of index(二) Embedded and document Index
查看>>
【MonogDB】The description of index(三) Compose and unique Index
查看>>