-4

Can someone explain to me what the ** after Cat is for? If it's a pointer to a pointer, shouldn't there be a space?

    Cat fetch_and_kill_oldest(Cat** cat_array, int length){
    //This function tries to find the oldest cat, take away one life,
        Cat temp = cat_array[0];
        for(int i = 1; i < length; i++){
            if (cat_array[i].age > temp.age){
                temp = cat_array[i];
            }
        }
        temp.lives -= 1;
        return temp;
        //stop here
    }
dbush
  • 205,898
  • 23
  • 218
  • 273
  • In `Cat**` it means that the author has bad taste. – Iharob Al Asimi May 18 '16 at 16:44
  • "If it's a pointer to a pointer, shouldn't there be a space?": No space needed. `**` is not a token, so that parser recognizes it as two separate `*` tokens. – Michael Burr May 18 '16 at 16:45
  • This is not a dup of the proposed question. OP knows what the `**` operator is for, he just doesn't understand what it means when there's no space between it and the type name. – dbush May 18 '16 at 16:55
  • @vaultah No is not a duplicate. The OP doesn't ask what `**` means. Please read the Question Again. =>> `shouldn't there be a space?` – Michi May 18 '16 at 17:06

1 Answers1

4

This:

Cat** cat_array

Is the same as this:

Cat **cat_array

The latter is preferred because it's more clear what the pointers refer to. For example, if you had a declaration like this:

int* a, b;

At first glance it might appear that a and b are both pointers, when in fact only a is a pointer. By formatting it the following way it's more apparent:

int *a, b;
dbush
  • 205,898
  • 23
  • 218
  • 273