For pointers, I’m getting confused with declarations and function parameters on when to use char ** or char * or *array[n], etc. Like if a function takes a (*array[n]) parameter, do I pass it a **type?
I try using the Right-Left rule and know that p would be a pointer to a pointer to a char (char **p), and p is an array of n pointers (*p[n]), but someone said that *p[n] and **p are essentially equivalent. Is that true?
Reading C declarators (that’s the part of the variable with the * and []) is fairly nuanced. There are some websites with tips:
A
char**is a pointer to (possible multiple) pointer(s) to (possibly multiple) char(s). For example, it might be a pointer to a string pointer, or a pointer to an array of string pointers.A
char*[]is an array of pointers to char. When you have a function that takes this as a parameter, the C compiler makes it “decay” into achar**. This only happens to the first layer… so, taking a complicated example,char*[4][]becomeschar*(*)[4]. Read the links above so you can understand what the heck that means.Or you can do a (very sensible) thing and make a bunch of typedefs. I don’t do this, but until you’re good at reading declarators, it’s a good idea.