数组的大小传递给C ++函数? [英] size of array passed to C++ function?
本文介绍了数组的大小传递给C ++函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能显示的文件:结果
<一href=\"http://stackoverflow.com/questions/1975128/sizeof-an-array-in-the-c-programming-language\">Sizeof在C编程语言中数组?结果
<一href=\"http://stackoverflow.com/questions/968001/determine-size-of-array-if-passed-to-function\">determine如果传递数组的大小的功能
我怎样才能得到一个C的大小传递给函数++数组?
How can I get the size of a C++ array that is passed to a function?
在以下code时,的sizeof(p_vertData)
不返回数组的正确大小。
In the following code, the sizeof(p_vertData)
does not return the correct size of the array.
float verts[] = {
-1.0,1.0,1.0,
1.0,1.0,1.0,
1.0,-1.0,1.0,
-1.0,-1.0,1.0,
-1.0,1.0,-1.0,
1.0,1.0,-1.0,
1.0,-1.0,-1.0,
-1.0,-1.0,-1.0
};
void makeVectorData(float p_vertData[]) {
int num = (sizeof(p_vertData)/sizeof(int));
cout << "output: " << num << endl;
};
我在做什么错了?
What am I doing wrong?
推荐答案
您不能 - 数组衰变时作为功能参数传递指针,所以sizeof的是不会帮你。
You can't - arrays decay to pointers when passed as function parameters so sizeof is not going to help you.
这篇关于数组的大小传递给C ++函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文