Skip to content

Instantly share code, notes, and snippets.

@iwagaki
Created January 27, 2015 09:21
Show Gist options
  • Save iwagaki/5f6882b208a4c1c2864b to your computer and use it in GitHub Desktop.
Save iwagaki/5f6882b208a4c1c2864b to your computer and use it in GitHub Desktop.
recursive strlen
#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