I learned by this question that incrementing a NULL pointer or incrementing past the end of an array isn't well-defined behavior:
int* pointer = 0;
pointer++;
int a[3];
int* pointer2 = &a[0];
pointer2 += 4;
But what If the pointer pointing to a invalid place is only used for comparison and memory at his location is never accessed?
Example:
void exampleFunction(int arrayLen, char** strArray)
{
for(char** str = strArray; str < strArray + arrayLen; str++) //or even str < &strArray[arrayLen]
{
//here *str is always a pointer to the first char of my string
}
}
Here I compare my pointer to a pointer one element past the end of the array. Is this well-defined behavior?