# Data Structure Questions and Answers-Length of a String using Recursion

## Click on any option to know the CORRECT ANSWERS

 Question 1
Consider the following iterative implementation to find the length of the string:

#include<stdio.h> int get....len(char *s) { int len = 0; while(.....) len++; return len; } int main() { char *s = "harsh"; int len = get....len(s); printf("%d", len); return 0; }

Which of the following lines should be inserted to complete the above code?

 A s[len-1] != 0 B s[len+1] != 0 C s[len] != ' D none of the mentioned

Question 1 Explanation:
The line "s[len] != '\0'" should be inserted to complete the above code.

 Question 2
What is the output of the following code?

#include<stdio.h> int get....len(char *s) { int len = 0; while(s[len] != '\0') len++; return len; } int main() { char *s = "lengthofstring"; int len = get....len(s); printf("%d", len); return 0; }
 A 14 B 0 C Compile time error D Runtime error

Question 2 Explanation:
The program prints the length of the string "lengthofstring", which is 14.

 Question 3
What is the time complexity of the above code used to find the length of the string?
 A O(1) B O(n) C O(n2) D O(logn)

Question 3 Explanation:
The time complexity of the code used to find the length of the string is O(n).

 Question 4
What is the output of the following code?

#include<stdio.h> int get....len(char *s) { int len = 0; while(s[len] != '\0') len++; return len; } int main() { char *s = ""; int len = get....len(s); printf("%d", len); return 0; }
 A 0 B 1 C Runtime error D Garbage value