so I'm having a little bit of difficulty using sizeof() to determine the length of an array. For clarity, here is my code:
int main(){
char array[] = "Cats";
printf("The size of this array is: %i",sizeof(array));
}
And rightly so, this outputs
The size of this array is: 5
My problem starts when I try to use the sizeof operator within a function, and then call that function from main. Like this:
void thefunct(char string[]){
printf("%i",sizeof(string));
}
and the call in main:
int main(){
thefunct("Cats");
}
In this case, this outputs 4, which is the size in bytes of the pointer for a character array. So basically, my question is: Why does it produce a '5' when I use sizeof directly in main(), but a '4' when I'm calling it from a separate function?
All answers are appreciated :)