Program in C and C++ to find the length of the string using recursive function
C Program
#include<stdio.h> int len(char *str){ static int i = -1; i += 1; if(str[i] == '\0') return 0; else len(str); return i; } int main(){ char str[] = "om prakash"; printf("Length : %d",len(str)); return 0; }
C++ Program
#include<iostream> using namespace std; int len(char *str){ static int i = -1; i += 1; if(str[i] == '\0') return 0; else len(str); return i; } int main(){ char str[] = "programming.om"; cout<<"Length : "<<len(str); return 0; }
Output :-
0 Comments