Created
January 27, 2015 09:21
-
-
Save iwagaki/5f6882b208a4c1c2864b to your computer and use it in GitHub Desktop.
recursive strlen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
int my_strlen(char* str) { | |
if (*str == 0) | |
return 0; | |
else | |
return my_strlen(str + 1) + 1; | |
} | |
int main() { | |
char str[] = "Hello, world!"; | |
int len = my_strlen(str); | |
printf("len = %d\n", len); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment