为什么不允许按值将数组传递给C和C ++中的函数? [英] Why it is not allowed to pass arrays by value to a function in C and C++?
本文介绍了为什么不允许按值将数组传递给C和C ++中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C和C ++允许按值将结构和对象传递给函数,尽管可以防止按值传递数组.
C and C++ allows passing of structure and objects by value to function, although prevents passing arrays by values.
为什么?
推荐答案
在C/C ++中,内部将数组作为指向某个位置的指针传递,基本上,是通过值传递.事实是,复制的值表示相同位置的内存地址.
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 ++中,vector<T>
被复制并传递给另一个函数.
In C++, a vector<T>
is copied and passed to another function, by the way.
这篇关于为什么不允许按值将数组传递给C和C ++中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文