简体   繁体   English

不明白array-1是什么意思

[英]Don't understand what array-1 means

I have a problem with understanding this code, especially the "vet-1" part. 我在理解此代码时遇到问题,尤其是“ vet-1”部分。 What does it mean? 这是什么意思? What item of the array does it return? 它返回数组的哪一项? Thanks 谢谢

#include <stdlib>
#include <iostream>

using namespace std;

void change( int m, int n[7]);

int main(){
int vet[] = {1,2,3,4,5};
change(vet[4],vet-1);
change(0,&vet[4]);
int i=0;
for (i=0;i<5;i++) cout << vet[i];
return 0;
}

void change( int m, int n[7]) {
(*(n+m))--; m++; n--;
}

vet - 1 is an attempt at referring to the pointer to the element just before vet[0] . vet - 1试图引用指向vet[0] 之前的元素的指针。

Actually the behaviour on doing that is undefined . 实际上,这样做的行为是不确定的 So the entire program is undefined. 因此,整个程序是不确定的。

Nothing to understand here; 这里什么都不懂; move on! 继续!

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

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