C Programming Questions and Answers:: Strings

@ : Home > C Programming Questions and Answers > Strings > General Questions

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);
}

Which of the following function is more appropriate for reading in a multi-word string?

A. printf();
B. scanf();
C gets();
D. puts();

Which of the following function is used to find the first occurrence of a given string in another string?

A. strchr()
B. strrchr()
C strstr()
D. strnset()

The library function used to find the last occurrence of a character in a string is

A. strnstr()
B. laststr()
C strrchr()
D. strstr()

How will you print \n on the screen?

A. printf("\n");
B. echo "\\n";
C printf('\n');
D. printf("\\n");

Page 1 of 2