Would it be possible to compare the two strings by address in this case as an alternative method? Or is that what the string compare standard function does.
There's nothing to stop you from doing an address compare, but there's no reason you would want to here. That's what my metaphor about the two balls in your two hands is supposed to convey. You have two different arrays. An address compare will always come up not-equal, no matter what's in the arrays. It will only tell you if you have two pointers that reference the same chunk of memory. That is, it will tell you if you have two hands on the same ball--not whether you are holding two identical balls.
The string compare function is better than my simple example in that it doesn't have the string-length bug, but this is roughly what it would do--walk through the strings comparing each character one at a time.
This is where an address compare would work:
Code:
const char string_one[] = "a string";
const char string_two[] = "a string";
char * a_pointer = string_one;
if ( a_pointer == string_two )
printf("this is not possible");
if ( a_pointer == string_one )
printf("we stored the address of the first string.");
About the only way an address compare is going to be useful is in a highly contrived example. Chances are that it's not what you want. It's
possible that it could be useful at some point, but there's probably a clearer way to write your code if you're ever thinking it's a good idea.
One exception: you should always do an address compare inside operator=() in C++, as there's no reason to bother with the assignment code if you're assigning an object to itself. But really, that's just a safeguard.