Strings

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

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

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

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

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

ANS:A -

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

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[] = "AptitudeCrack";
    printf("Length = %d\n", xstrlen(d));
    return 0;
}
Output: Length = 8



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.