Nanton Zhang Nanton Zhang - 1 year ago 74
C Question

return 1 + strlen_rec(&arr[1]) ;this sentence confused me a lot

Here's the code.

int strlen_rec(char arr[])

return 0;
return 1 + strlen_rec(&arr[1]) ;

Answer Source

This function counts the length of a string using recursion. It may look confusing since it's using an array like a pointer. &ar[1] is increasing the pointer (calling the function with the address of the next byte). C strings are terminated with a null byte which isn't included in the length so it returns 0 when reached.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download