博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c/c++ 传引用,数组传引用 区别
阅读量:2353 次
发布时间:2019-05-10

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

c 语言传引用,数组传引用

 

#include <stdlib.h>

#include <stdio.h>

 

void test1(int *x)

{

    *x = 1000;

}

 

void test2(int *y)

{

    y[0] = 1111;

}

 

void test3(int *z)

{

    *z = 2222;

}

 

int main(int argc, char *argv[])

{

    int x = 1, i = 0;

    int y[4] = {1, 1, 1, 1};

    int *z = 1;

 

    z = (int *)malloc(sizeof(int));

 

    test1(&x);

    test2(y);

    test3(z);

 

    printf("x: %d/n", x);

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

        printf("y[%d]: %d/n", i, y[i]);

 

    printf("z: %d/n", *z);

 

    return 0;

}

 

输出结果:

x: 1000

y[0]: 1111

y[1]: 1

y[2]: 1

y[3]: 1

z: 2222

 

 

c++ 传引用

#include <iostream>
using namespace std;
void test(int&);
main()
{
    int a = 1;
    test(a);
    printf("a: %d/n", a); 
}
void test(int& a)
{
    a = 100;
}
输出结果:
a: 100

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

你可能感兴趣的文章
STM32 HAL库、标准外设库、LL库(STM32 Embedded Software)
查看>>
51和AVR单片机
查看>>
DSP开发板
查看>>
stm32标准外设库和芯片资料下载地址
查看>>
ARM Keil MDK开发STM32工程模板
查看>>
NoSQL分类及常用软件
查看>>
ubuntu 16.04安装nVidia显卡驱动和cuda/cudnn踩坑过程
查看>>
基于STM32CubeMX创建STM32L496ZGTx的工程
查看>>
如何通过OpenFace实现人脸识别框架
查看>>
Angle和XBGoost以及Spark的性能对比
查看>>
IOS CoreImage实现人脸识别
查看>>
Tensorflow的高级封装
查看>>
Storm 1.1.0 集群安装
查看>>
图像压缩算法
查看>>
一张图看懂小程序全生态
查看>>
electron开发
查看>>
NodeJS开发c++扩展模块
查看>>
Electron如何调用NodeJS扩展模块
查看>>
NodeJS通过ffi调用DLL
查看>>
Electron通过ffi调用DLL
查看>>