How is arr[j]=arr[j-1] valid here, because we cant use assignment operator for two strings

void string_sort(char** arr,const int len,int (*cmp_func)(const char* a, const char* b)){
    for(int i = 1; i < len; i++){
        int j = i;
        char* p = arr[i];
        while(j > 0){
            if((*cmp_func)(arr[j-1],p) > 0 )
                arr[j] = arr[j-1];
        arr[j] = p;

Assignment with array type (on the left) is not allowed. But assigning array type (on the right) is fine. Consider the following program :

void basic_version (char* a, char* b) {
    a = b;

int main () {
    char a[] = "negla"
    char b[] = "pandey_adm"
    basic_version (a, b);

Note that char* has no problems with assignment (on either side).

To put it concisely : there are no string/char [] involved in string_sort. Its just char pointers and pointers to them.

1 Like