This is a C code. The aim of the function is to add data which is defined using data pointers ‘*data’
int chksum(int *data) {
char j;
int summation = 0;
for (j = 0; j < 64; j++) {
summation += data[j]
}
return summation;
}
But I am not able to understand that how the data given by the pointer ‘*data’ is getting added using summation += data[j].
My understanding says, the code should be like this:
int chksum(int *data) {
char j;
int summation = 0;
for (j = 0; j < 64; j++) {
summation += *(data++)
}
return summation;
}
>Solution :
We could use *(data++).
But surely you see that’s the same as *(data+j).
And since data[j] is equivalent to *(data+j) by definition, we could also use data[j].