简体   繁体   English

如果a是一个数组,那么函数(1,a + 2)中的加法意味着什么?

[英]What does the addition mean in function(1,a+2) if a is an array?

I was looking at this piece of code and I'm not sure what the addition means if "a" is an array. 我正在查看这段代码,如果“a”是一个数组,我不确定添加意味着什么。

int main(int argc, char* argv[]){
int a[] = {1, 3, 5, 7, 9};

function(1, a+2);
return 0;}

Assume the function is already created. 假设已经创建了该功能。

In an expression (except when used with sizeof or &), an array name is a pointer to the first element in the array. 在表达式中(与sizeof或&一起使用时除外),数组名称是指向数组中第一个元素的指针。 So a+2 is "pointer arithmetic" on that pointer, and results in a pointer to the element at offset 2. It is equivalent to &a[2] . 所以a+2是指针上的“指针算术”,并产生指向偏移量为2的元素的指针。它相当于&a[2]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM