I seem to be a able to compare a between 2 strings literals without dereferencing them.
To be more exact, you're comparing pointers to string literals, not the literals themselves.
Should i not do a *name==*name instead?
If you intend to compare only the first character, then yes, although tail->name[0] == name[0]
would be more descriptive in my opinion.
If you intend to compare contents of the string, then you must dereference the pointers and iterate through each string in parallel, comparing the characters along the way. A standard function exists for that: std::strcmp
.
If you instead want to compare the pointers, then what you're doing currently is correct. Do note that identical but separate string literals are not guaranteed to have the same address, so this might not work as you may intend it to. It depends on your use case, whether this approach is appropriate.
I'll try to explain with an example:
const char* argument = "test";
const char* name = argument;
const char* another_name = argument;
assert(name == another_name);
The assertion is guaranteed to be true, there should be nothing strange about it. The pointers are copies of each other and point to the same address which is where the string literal is stored.
However:
const char* name = "test";
const char* another_name = "test";
assert(name == another_name);
This assertion is not guaranteed to be true. But it is not guaranteed to be false either. It is unspecified and up to the implementation. It should not be surprising that the identical string literals could have the same address, it's a common optimisation. But you cannot rely on that. In this situation, compare the contents of the string rather than the address, as explained earlier in the answer.