logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings Comments

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

  • Correct Answer
  • strnset() 

    Explanation
    Declaration:

    char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch

    #include <stdio.h>
    #include <string.h>
    
    int main(void)
    {
       char *string = "abcdefghijklmnopqrstuvwxyz";
       char letter = 'x';
    
       printf("string before strnset: %s\n", string);
       strnset(string, letter, 13);
       printf("string after  strnset: %s\n", string);
    
       return 0;
    }
    

    Output:

    string before strnset: abcdefghijklmnopqrstuvwxyz

    string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz


    Strings problems


    Search Results


    • 1. 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
    • 2. How will you print \n on the screen?

    • Options
    • A. printf("\n");
    • B. echo "\\n";
    • C. printf('\n');
    • D. printf("\\n");
    • Discuss
    • 3. 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
    • 4. What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

    • Options
    • A. ((((a+i)+j)+k)+l)
    • B. *(*(*(*(a+i)+j)+k)+l)
    • C. (((a+i)+j)+k+l)
    • D. ((a+i)+j+k+l)
    • Discuss
    • 5. How many bytes are occupied by near, far and huge pointers (DOS)?

    • Options
    • A. near=2 far=4 huge=4
    • B. near=4 far=8 huge=8
    • C. near=2 far=4 huge=8
    • D. near=4 far=4 huge=8
    • Discuss
    • 6. If the two strings are identical, then strcmp() function returns

    • Options
    • A. -1
    • B. 1
    • C. 0
    • D. Yes
    • Discuss
    • 7. 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
    • 8. 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
    • 9. To scan a and b given below, which of the following scanf() statement will you use?
      #include<stdio.h>
      
      float a;
      double b;
      

    • Options
    • A. scanf("%f %f", &a, &b);
    • B. scanf("%Lf %Lf", &a, &b);
    • C. scanf("%f %Lf", &a, &b);
    • D. scanf("%f %lf", &a, &b);
    • Discuss
    • 10. Out of fgets() and gets() which function is safe to use?

    • Options
    • A. gets()
    • B. fgets()
    • Discuss


    Comments

    There are no comments.

Enter a new Comment