So, I did the following test:
char* a = "test"; char* b = "test"; char* c = "test\0";
And now the questions:
1) Is it guaranteed that a==b
? I know I'm comparing addresses. This is not intended to compare strings, but are string literals identical in the same memory location?
2) Why not a==c
? Can't the compiler see that they are on the same line?
3) Is an extra \0
added at the end of c
, although it already contains one?
I did not want to ask three different questions for this, because they seem to be somehow connected, excuse me for that.
Note. The tag is correct, I'm interested in C ++. (although please indicate if C behavior is different)
source share