Before I continue with another operation, I need to make sure that "p1 + 1" is positioned before another value in the same sequance. Im not used to comparing addresses, is this a valid way to check that?
As long as both p1 + 1 and p2 point to the same array or one element past the end of the array then the comparison is valid. If this is not true, the behavior is undefined.
If possible, I would avoid these sorts of comparisons and restructure the code to deal with indices instead:
A C-style string is simply an array of characters that uses a null terminator. A null terminator is a special character (‘\0’, ascii code 0) used to indicate the end of the string. More generically, A C-style string is called a null-terminated string.
To define a C-style string, simply declare a char array and initialize it with a string literal:
1
char myString[]{ "string" };
Although “string” only has 6 letters, C++ automatically adds a null terminator to the end of the string for us (we don’t need to include it ourselves). Consequently, myString is actually an array of length 7!
If you need to compare arbitrary pointers you should first convert them to uintptr_t or intptr_t.
Can you give me a good example of this?
The details at that level aren't really important.
No, but they're interesting. And because we can compare an address in our array to an address that's outside the sequance (last + 1) Thats should mean that this is automatically added somehow, else it would be undefined behavior .
And because we can compare an address in our array to an address that's outside the sequance (last + 1) Thats should mean that this is automatically added somehow
I don't know what you mean by "this" when you say "this is added". I have no idea what you're imagining in your head.
That's just what the language guarantees. In reality the implementation will have no choice (without expending additional effort that nobody would want) but to allow comparisons well past the end of an array. It depends on how the objects fall in memory and how the platform stores pointers. The standard is telling you that if you rely on pointer comparisons between unrelated objects your code may behave unpredictably.