Program for length of a string using recursion | CPP program to calculate length of a string using recursion ; Function to calculate length ; if we reach at the end of the string ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int recLen ( char * str ) { if ( * str == ' \0' ) return 0 ; else return 1 + recLen ( str + 1 ) ; } int main ( ) { char str [ ] = " GeeksforGeeks " ; cout << recLen ( str ) ; return 0 ; }