I’m trying to implement a strlen
function in C with recursion and for some reason it’s returning a 4 times bigger value than expected.
int *strlen(char *s)
{
if(*s == '\0')
return 0;
else
return 1 + strlen(s+1);
}
Interestingly, when I change the type return of the function to "char", I get the desired result. I don’t understand why, it should return an int anyways. I copied this code from a book, it should be right.
You need to sign in to view this answers