简体   繁体   中英

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.

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. 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] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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