为什么C或C ++不允许通过值传递数组的功能 [英] Why C or C++ does not allow passing array by values to function

查看:136
本文介绍了为什么C或C ++不允许通过值传递数组的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C和C ++允许结构传递和对象按值的功能,虽然prevents传递数组由值,为什么?

C and C++ allows passing of structure and objects by value to function, although prevents passing arrays by values, why?

推荐答案

在C / C ++,在内部,一个数组的指针一些位置过去了,基本上,它的的值传递。问题是,那个复制的转口货值为presents一个内存地址到的相同的位置的。

In C/C++, internally, an array is passed as a pointer to some location, and basically, it is passed by value. The thing is, that copied value represents a memory address to the same location.

在C ++中,矢量< T> 复制并传递给另一个函数,顺便

In C++, a vector<T> is copied and passed to another function, by the way.

这篇关于为什么C或C ++不允许通过值传递数组的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆