The Cost of Recursion
By Jon Bentley
Dr. Dobb's Journal June 1998
<B>(a)</B> int istrlen(char *s) { int n = 0; for ( ; *s; s++) n++; return n; } <B>(b)</B> int rstrlen(char *s) { if (*s) return 1+rstrlen(s+1); else return 0; }
Example 1: (a) Typical implementation of strings; (b) implementing the function recursively.
Copyright © 1998, Dr. Dobb's Journal