Comparison of string characters

Hello everybody,

I'm new to C++, taking my first course in college. In my reading, I'm stumped by how string values are compared. According to the book:

"Bill" > "BILL"

"Bill" > "Bob"

"Mary" > "MaryEllen"

I understand the first one. The B in Bill is compared to the B in BILL, their ASCII values found equal, then the i in Bill is compared to the I in BILL, and the ASCII value for i is greater than the ASCII value for I.

But how does the second one work? What letter in Bill is being compared to what letter in Bob? Likewise, what is the corresponding characters in Mary and MaryEllen?

Thank you in advance for your help!
That doesn't compare the strings. It compares the pointer to the string. if you want to compare the strings use 'strcmp()' or similar
In C++, this doesn't work at all because string literals are const char*. The rules for comparing strings aren't set in stone, I suppose that "Mary" > "MaryEllen" because there was some rule set up that said that if one word is the compound of another it is smaller or something.
Topic archived. No new replies allowed.