logo

CuriousTab

CuriousTab

Strings problems


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

  • Options
  • A. strchr()
  • B. strrchr()
  • C. strstr()
  • D. strnset()
  • Discuss
  • 2. How will you print \n on the screen?

  • Options
  • A. printf("\n");
  • B. echo "\\n";
  • C. printf('\n');
  • D. printf("\\n");
  • Discuss
  • 3. The library function used to find the last occurrence of a character in a string is

  • Options
  • A. strnstr()
  • B. laststr()
  • C. strrchr()
  • D. strstr()
  • Discuss
  • 4. Which of the following function sets first n characters of a string to a given character?

  • Options
  • A. strinit()
  • B. strnset()
  • C. strset()
  • D. strcset()
  • Discuss
  • 5. If the two strings are identical, then strcmp() function returns

  • Options
  • A. -1
  • B. 1
  • C. 0
  • D. Yes
  • Discuss
  • 6. Which of the following function is correct that finds the length of a string?

  • Options
  • 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);
    }
    
  • Discuss
  • 7. Which of the following function is more appropriate for reading in a multi-word string?

  • Options
  • A. printf();
  • B. scanf();
  • C. gets();
  • D. puts();
  • Discuss
  • 8. What will be the output of the program?
    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
        static char s[] = "Hello!";
        printf("%d\n", *(s+strlen(s)));
        return 0;
    }
    

  • Options
  • A. 8
  • B. 0
  • C. 16
  • D. Error
  • Discuss
  • 9. What will be the output of the program?
    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
        char str1[20] = "Hello", str2[20] = " World";
        printf("%s\n", strcpy(str2, strcat(str1, str2)));
        return 0;
    }
    

  • Options
  • A. Hello
  • B. World
  • C. Hello World
  • D. WorldHello
  • Discuss
  • 10. What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        char str1[] = "Hello";
        char str2[] = "Hello";
        if(str1 == str2)
            printf("Equal\n");
        else
            printf("Unequal\n");
        return 0;
    }
    

  • Options
  • A. Equal
  • B. Unequal
  • C. Error
  • D. None of above
  • Discuss

First 2 3 4 5