J
John Tsiombikas (Nuclear / the Lab)
I know what they mean. var is a variable. A place in memory for an int.
And *var is a pointer to a location in memory that is an int. What I confuse
is how to use this in function parameters.
For example int function(void**)
That's a pointer to a pointer to a void. But what do you do with it in
code ?
Bill
You may need to pass to a function a pointer to a pointer for various
reasons. For example you may want to pass an array of strings to a
function and use it like this:
void foo(char **str_array, int count) {
int i;
for(i=0; i<count; i++) {
printf("string[%d]: %s\n", i, str_array);
}
}
or you may have a pointer that you want to change inside that function,
for example:
void foo(int **bar) {
if(*bar == 0) {
*bar = malloc(sizeof(int));
}
**bar = 10;
}