美文网首页工作生活
c++中函数传入数组是指针,不是拷贝

c++中函数传入数组是指针,不是拷贝

作者: 设置一个看起来合理的昵称 | 来源:发表于2019-07-01 16:01 被阅读0次
#include <iostream>

void detail(int arr[]){
    arr[0] = 1;
    std::cout << arr << std::endl; //输出0x7ffeefbff59c
}

int main(int argc, const char * argv[]) {
    int arr[1];
    arr[0] = 0;
    std::cout << arr << std::endl; // 输出0x7ffeefbff59c
    std::cout << arr[0] << std::endl; //输出0
    detail(arr);
    std::cout << arr[0] << std::endl; //输出1
    return 0;
}

//c++中函数参数传数组时并没有复制数组,而是传了数组首地址对应的指针。

相关文章

网友评论

    本文标题:c++中函数传入数组是指针,不是拷贝

    本文链接:https://www.haomeiwen.com/subject/buzgcctx.html