I have a problem with understanding this code, especially the "vet-1" part. 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]
.
Actually the behaviour on doing that is undefined . So the entire program is undefined.
Nothing to understand here; move on!
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.