What is the time complexity of the following code used to find the length of the string? [code] #include<stdio.h> int get_len(char *s) {

What is the time complexity of the following code used to find the length of the string?
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. O(1)
B. O(n)
C. O(n$^{2}$)
D. O(logn)
 

Tìm kiếm

Back
Top