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

    View Answer

    Workspace

    Discuss Discuss in Forum


  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()

    View Answer

    Workspace

    Discuss Discuss in Forum


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

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

    View Answer

    Workspace

    Discuss Discuss in Forum


  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()

    View Answer

    Workspace

    Discuss Discuss in Forum


  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()

    View Answer

    Workspace

    Discuss Discuss in Forum


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

    View Answer

    Workspace

    Discuss Discuss in Forum


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

     

    View Answer

    Workspace

    Discuss Discuss in Forum