Why should I create a new void**
variable when I can simply &
to the original variable? Are double-pointer variables useless?
Please note I'm not discussing the double-pointer
concept. I'm talking about creating a double-pointer variable instead of just using a reference. I'm about the coding style, not the concept.
void update(char** foo) {
char* buf = (char*) malloc(32);
sprintf(buf, "Hello World");
*foo = buf;
}
int main() {
char* foo = NULL;
// Using a char** variable (The long way)
char** bar = &foo;
update(bar);
printf("Using a new variable -> foo = %s.\n", *bar);
// Using reference (The quick way)
update(&foo);
printf("Using a simple reference -> foo = %s.", foo);
return 0;
}