Question: I know I shouldn't use C-style arrays but I was trying to look for a way to do this anyway. I'm trying to alphabetize the `const char*` array but `std::sort` didn't do it right. What am I doing wrong?

```
#include <iostream>
#include <algorithm>

int main() {

   const char * str[5] = {"alpha", "gamma", "beta", "delta", "chi"};

   int size = sizeof(str)/sizeof(*str);

   std::sort(str, str + size);

   for (int i = 0; i < size; i++) std::cout << str[i] << ", ";

}

```

It doesn't change the array at all. What am I not doing right?

Answer: 
The default `std::sort` comparison function is simply comparing *pointers* (memory addresses) with the `<` operator. It's not actually lexicographically comparing the C-strings. You need to create a custom comparison function which compares the strings lexicographically by e.g. calling `std::strcmp`

```
bool compare(const char* s1, const char* s2)
{
    return std::strcmp(s1, s2) < 0;
}

int main() 
{
   const char * str[5] = {"alpha", "gamma", "beta", "delta", "chi"};
   int size = sizeof(str)/sizeof(*str);
   std::sort(str, str + size, compare);
   for (int i = 0; i < size; i++) std::cout << str[i] << ", ";
}

```
Maybe because the default comparator for `const char *` is comparing pointer values (and the string constants happen to be allocated in the array order already)?

Use `std::string`.