If I were to have this code, for example:
int num = 5;
int *ptr = #
What is the difference between the following two functions?:
void func(int **foo);
void func(int *foo);
The first one wants a pointer to a pointer to an int, the second one wants a pointer which directly points to an int.
Where I call the function:
func(&ptr);
As ptr is a pointer to an int, &ptr is an address, compatible with a int **.
The function taking a int * will do somethin different as with int **. The result of the conversation will be completely different, leading to undefined behaviour, maybe causing a crash.
If I pass in func(&ptr) I am effectively passing in a pointer. What difference does it make that the pointer points to another pointer?
+++++++++++++++++++
adr1 (ptr): + adr2 +
+++++++++++++++++++
+++++++++++++++++++
adr2 (num): + 42 +
+++++++++++++++++++
At adr2, we have an int value, 42.
At adr1, we have the address adr2, having the size of a pointer.
&ptr gives us adr1, ptr, holds the value of &num, which is adr2.
If I use adr1 as an int *, adr2 will be mis-treated as an integer, leading to a (possibly quite big) number.
If I use adr2 as an int **, the first dereference leads to 42, which will be mis-interpreted as an address and possibly make the program crash.
It is more than just optics to have a difference between int * and int **.
I believe the latter will give an incompatibility warning,
... which has a meaning ...
but it seems that the details do not matter so long as you know what you are doing.
Do you?
It seems that perhaps for the sake of readability and understanding the former is a better option (2-star pointer), but from a logical standpoint, what is the difference?
It depends on what the function does with the pointer.
func(), one line after the other. That's a compiler error right there, so you cannot pass either of them anything, and therefore everything after that is just nonsense. [This is an intentionally facetious comment intented to make sherrellbc think about why people people use obvious shorthand when asking a question -- and when they answer]. ;)