C Questions and Answers – String Operations – 1

«
»

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.

advertisement

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

Answer: a
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

Answer: b
Explanation: The given code char *strchr(ch, c) return pointer to first occurrence of c in ch or NULL if not present.
advertisement
advertisement

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

Answer: b
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

Answer: a
Explanation: int strncmp(ch, s, n) is used to compare at most n characters of string ch to string s; return <0 if ch0 of ch >s.
advertisement

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

Answer: c
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

Answer: b
Explanation: The mem functions is used for manipulating objects as character arrays.
advertisement

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

Answer: b
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

Answer: c
Explanation: Functions whose names begin with “strn” manipulates the sequence of non-null characters.
advertisement

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

Answer: a
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

Answer: a
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.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.