While reading some tutorials on the net about the C language, I found the following code that allocates memory for an array of length (n1-n0+1). I can't figure out how and why adding this instruction: v -= n0;
works. Here is the code:
double *AllocVector(int n0, int n1)
{
double *v;
int i;
v = malloc((n1-n0+1) * sizeof(double));
if (!v)
printf("Error allocating memory in AllocVector");
/* Initiate */
v -= n0;
for (i = n0; i <= n1; i++)
v[i] = 0.0;
return v;
}