This set of C Multiple Choice Questions & Answers (MCQs) focuses on “String Operations – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. There are two groups of string functions defined in the header <string.h>. What are they?
a) first group names beginning with str; second group names beginning with mem
b) first group names beginning with str; second group names beginning with is
c) first group names beginning with string; second group names beginning with mem
d) first group names beginning with str; second group names beginning with type
View Answer
Explanation: There are two groups of string functions declared under the header <string.h>. The first have names beginning with str and second have names beginning with mem.
2. What is the use of function char *strchr(ch, c)?
a) return pointer to first occurrence of ch in c or NULL if not present
b) return pointer to first occurrence of c in ch or NULL if not present
c) return pointer to first occurrence of ch in c or ignores if not present
d) return pointer to first occurrence of cin ch or ignores if not present
View Answer
Explanation: The given code char *strchr(ch, c) return pointer to first occurrence of c in ch or NULL if not present.
3. Which code from the given option return pointer to last occurrence of c in ch or NULL if not present?
a) char *strchr(ch, c)
b) char *strrchr(ch, c)
c) char *strncat(ch, c)
d) char *strcat(ch, c)
View Answer
Explanation: The function char *strrchr(ch, c) returns pointer to last occurrence of c in ch or NULL if not present.
4. Which among the given options compares atmost n characters of string ch to string s?
a) int strncmp(ch, s, n)
b) int strcmp(ch, s)
c) int strncmp(s, ch, n)
d) int strcmp(s, ch)
View Answer
Explanation: int strncmp(ch, s, n) is used to compare at most n characters of string ch to string s; return <0 if ch
5. Which among the given options is the right explanation for the statement size_t strcspn(c, s)?
a) return length of prefix of s consisting of characters not in c
b) return length of prefix of s consisting of characters present in c
c) return length of prefix of c consisting of characters not in s
d) return length of prefix of c consisting of characters present in s
View Answer
Explanation: The function size_t strcspn(c, s) is used to return length of prefix of c consisting of characters not in s.
6. The mem functions are meant for _______
a) returning a pointer to the token
b) manipulating objects as character arrays
c) returning a pointer for implemented-defined string
d) returning a pointer to first occurrence of string in another string
View Answer
Explanation: The mem functions is used for manipulating objects as character arrays.
7. What is the function of void *memset(s, c, n)?
a) places character s into first n characters of c, return c
b) places character c into first n characters of s, return s
c) places character s into first n characters of c, return s
d) places character c into first n character of s, return c
View Answer
Explanation: The void *memset(s, c, n) places character c into first n characters of s, return s.
8. Functions whose names begin with “strn”
a) manipulates sequences of arbitrary characters
b) manipulates null-terminated sequences of characters
c) manipulates sequence of non – null characters.
d) returns a pointer to the token
View Answer
Explanation: Functions whose names begin with “strn” manipulates the sequence of non-null characters.
9. Which of the following is the right syntax to copy n characters from the object pointed to by s2 into the object pointed to by s1?
a) void *memcpy(void *s1,const void *s2,size_t n);
b) void *memcpy(void *s2, const void *s1, size_t n);
c) void memcpy(void *s1,const void *s2, size_t n);
d) void memcpy(void *s2,const void *s1,size_t n);
View Answer
Explanation: The memcpy() function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.
10. What does the following function returns void *memmove(void *s1,const void s2, size_t n);?
a) returns the value of s1
b) returns the value of s2
c) doesn’t return any value
d) returns the value of s1 and s2
View Answer
Explanation: The memmove() function copies n characters from the object pointed to by s2 into the object pointed to by s1.The memmove() function returns the value of s1.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Apply for C Internship
- Practice Computer Science MCQs
- Practice BCA MCQs
- Watch Advanced C Programming Videos