Examveda

What is the time complexity of the following code used to find the length of the string?
#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. O(1)

B. O(n)

C. O(n2)

D. O(logn)

Answer: Option B


This Question Belongs to Data Structure >> Miscellaneous On Data Structures

Join The Discussion

Related Questions on Miscellaneous on Data Structures