Home » C Programming » Strings

Which of the following function is correct that finds the length of a string?

Correct Answer: int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }

Explanation:

Option A is the correct function to find the length of given string.


Example:


#include<stdio.h>

int xstrlen(char *s)
{
    int length=0;
    while(*s!='\0')
    { length++; s++; }
    return (length);
}

int main()
{
    char d[] = "CuriousTab";
    printf("Length = %d\n", xstrlen(d));
    return 0;
}

Output: Length = 8


← Previous Question Next Question→

More Questions from Strings

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion