COM SCI 31 Lecture Notes - Lecture 15: Semicolon, Empty String, Null Pointer
Document Summary
Findfirstnegative(double a[], int n){ for (double* dp = a; dp < a + n; dp++){ if (*dp < 0) return dp -a; // remember, &a[i] - &a[j] ===> i - j. // bytes apart they are, but rather how many elements apart they are. //(this can be negative) ++ return -1; int main(){ double da[5]; double* fnp = findfirstnegative(da, 5); if (fnp ) ++ note that if the pointers represent elements in different arrays, the resulting value will not make sense--subtraction of these pointers will result in the difference in there byte location in memory divided by 8. &x[2] - &y[0] ===> -6, because the values are 48 bytes apart. (does not. For each pointer type, there is a specific bit pattern that represents a pointer that does not point to anything. This value is the infamous null pointer value , and can be used for any pointer type.