4 ms·
From another perspective, they're both performing the same operation on different types. With what you'd call "destination passing", like char *buf = mall
by comex 6y ago
From another perspective, they're both performing the same operation on different types. With what you'd call "destination passing", like
char *buf = malloc(128);
snprintf(buf, 128, "hello");
the function is accepting a pointer to an uninitialized array of char, and initializing the array of char. With what you'd call an "out parameter", like
char *buf;
asprintf(&buf, "hello");
the function is accepting a pointer to an uninitialized pointer to array of char, and initializing the pointer. The caller still controls the allocation of storage for the pointer itself.