I understand if you have an array, and you do sizeof, it gives you the number of bytes that block of memory occupies, but I have some confusion regarding the follow situation.
int mylen(const char *str) {
return sizeof(str);
}
int main(void) {
char str[] = "hello";
printf("%d\n", sizeof(str)); // this gives 6
printf("%d\n", mylen(str)); // this gives 8
}
I understand mylen is just returning the sizeof char pointer, therefore 8, but in that case, why the first one works? It this the subtle distinction between str and char *?