Home / C Programming / Strings :: General Questions

C Programming :: Strings

  1. Which of the following statements are correct about the program below?

     #include
     
      int main() 
      {   
           char str[20], *s;     
           printf("Enter a string\n");     
           scanf("%s", str); 
           s=str;    
           while(*s != '\0')  
           {        
               if(*s >= 97 && *s 122)             
                   *s = *s-32;         
                s++;  
           }   
           printf("%s",str);  
           return 0;
      } 
    

  2. A.

    The code converts a string in to an integer

    B.

    The code converts lower case character to upper case

    C.

    The code converts upper case character to lower case

    D.

    Error in code


  3. Which of the following function sets first n characters of a string to a given character?

  4. A.

    strinit()

    B.

    strnset()

    C.

    strset()

    D.

    strcset()


  5. How will you print \n on the screen?

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

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

  8. A.

    strnstr()

    B.

    laststr()

    C.

    strrchr()

    D.

    strstr()


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

  10. A.

    strchr()

    B.

    strrchr()

    C.

    strstr()

    D.

    strnset()


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

  12. A.

    printf();

    B.

    scanf();

    C.

    gets();

    D.

    puts();


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

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