Hi,
I'm currently learning C and I'm noticing between the book I'm reading and source code on the net of the following pattern:
static void md5_hash(char *md5str, char *arg) {
PHP_MD5_CTX context;
unsigned char digest[16];
md5str[0] = '\0';
PHP_MD5Init(&context);
PHP_MD5Update(&context, arg, strlen(arg));
PHP_MD5Final(digest, &context);
make_digest(md5str, digest);
}
This is a snippet of mongo db source code. If you notice that one of the arguments is being passed a pointer as a parameter. But a few lines down, the variable is being passed to another function without the (*). I'm still a little confused. Aren't you suppose to always use the "*" when working with pointers within a function? I sometimes see the convention of always using the "*" and in other cases (like the code above), they don't bother with it.
Which one is it? The book doesn't seem to explain the different approaches.
Thanks
EDIT:
Here's another example that I wrote:
void myFunction(char stuff[]) {
printf("%s", stuff);
}
main(int argc, char *argv[]) {
myFunction(*argv);
return 0;
}
Arrays are passed by reference yet I cannot pass argv in main without the "*" as the compiler complains: