C语言 获取数组元素的地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4301829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get address for an array element
提问by VansFannel
I'm developing a C program and I have a question about pointers and arrays.
我正在开发一个 C 程序,我有一个关于指针和数组的问题。
I have the following arraypointer:
我有以下数组指针:
GLuint *vboIds;
And the following function prototype:
以及以下函数原型:
void glGenBuffers(GLsizei n, GLuint *buffers);
The following statement is correct:
以下说法是正确的:
glGenBuffers(1, vboIds);
But I want to pass to glGenBuffersthe second index of vboIds as second parameter for the function. I have put this:
但我想传递给glGenBuffersvboIds 的第二个索引作为函数的第二个参数。我已经把这个:
glGenBuffers(1, &&vboIds[1]);
Is this correct?
这样对吗?
Thanks.
谢谢。
回答by Christopher Creutzig
glGenBuffers(1, &(vboIds[1]));
or what Armen said,
或者Armen所说的,
glGenBuffers(1, vboIds + 1);
回答by Simone
Yes, it would be correct if you remove one ampersand.
是的,如果您删除一个&符号,那将是正确的。
You could also write glGenBuffers(1, vboIds + 1);.
你也可以写glGenBuffers(1, vboIds + 1);.
回答by Armen Tsirunyan
glGenBuffers(1, vboIds + 1);
回答by Matthew Flaschen
No, the double & is incorrect, and will not compile. If you do want to use that syntax, it's:
不,双 & 是不正确的,不会编译。如果您确实想使用该语法,则为:
glGenBuffers(1, &vboIds[1]);
This is completely equivalent to Armen's answer, which is the simplest way to do it.
这完全等同于Armen的答案,这是最简单的方法。
回答by Coding District
You only need one address of operator (&)
您只需要一个运算符地址 (&)
glGenBuffers(1, &vboIds[1]);

