C Questions and Answers – String Operations – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “String Operations – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. Which among the following is Copying function?
a) memcpy()
b) strcopy()
c) memcopy()
d) strxcpy()
View Answer

Answer: a
Explanation: The memcpy() function is used to copy n characters from the object.
The code is void *memcpy(void *s1,const void *s2, size_t n).

2. Which function will you choose to join two words?
a) strcpy()
b) strcat()
c) strncon()
d) memcon()
View Answer

Answer: b
Explanation: The strcat() function is used for concatenating two strings, appends a copy of the string.
char *strcat(char *s1,const char *s2);
advertisement
advertisement

3. The ______ function appends not more than n characters.
a) strcat()
b) strcon()
c) strncat()
d) memcat()
View Answer

Answer: c
Explanation: The strncat() function appends not more than n characters from the array(s2) to the end of the string(s1).char *strncat(char *s1, const char *s2,size_t n);

4. What will strcmp() function do?
a) compares the first n characters of the object
b) compares the string
c) undefined function
d) copies the string
View Answer

Answer: b
Explanation: The strcmp() function compares the string s1 to the string s2.
int strcmp(const char *s1,const char *s2);
advertisement

5. What is the prototype of strcoll() function?
a) int strcoll(const char *s1,const char *s2)
b) int strcoll(const char *s1)
c) int strcoll(const *s1,const *s2)
d) int strcoll(const *s1)
View Answer

Answer: a
Explanation: The prototype of strcoll() function is int strcoll(const char *s1,const char *s2).

6. What is the function of strcoll()?
a) compares the string, result is dependent on the LC_COLLATE
b) copies the string, result is dependent on the LC_COLLATE
c) compares the string, result is not dependent on the LC_COLLATE
d) copies the string, result is not dependent on the LC_COLLATE
View Answer

Answer: a
Explanation: The strcoll() function compares the string s1 to the string s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.
advertisement

7. Which of the following is the variable type defined in header string. h?
a) sizet
b) size
c) size_t
d) size-t
View Answer

Answer: c
Explanation: This is the unsigned integral type and is the result of the sizeof keyword.

8. NULL is the macro defined in the header string. h.
a) true
b) false
View Answer

Answer: a
Explanation: NULL macro is the value of a null pointer constant.

advertisement

9. What will be the output of the following C code?

const char pla[] = "string1";
const char src[] = "string2";
printf("Before memmove place= %s, src = %s\n", pla, src);
memmove(pla, src, 7);
printf("After memmove place = %s, src = %s\n", pla, src);

a) Before memmove place= string1, src = string2 After memmove place = string2, src = string2
b) Before memmove place = string2, src = string2 After memmove place= string1, src = string2
c) Before memmove place = string2, src = string1 After memmove place= string2, src =string2
d) Before memmove place= string1, src = string2 After memmove place=string1, src = string1
View Answer

Answer: a
Explanation: In the C library function void *memmove(void *str1, const void *str2, size_t n) copies n characters from str2 to str1.

10. What will be the output of the following C code?

const char str1[]="ABCDEF1234567";
const char str2[] = "269";
len = strcspn(str1, str2);
printf("First matching character is at %d\n", len + 1);

a) First matching character is at 8
b) First matching character is at 7
c) First matching character is at 9
d) First matching character is at 12
View Answer

Answer: a
Explanation: size_t strcspn(const char *str1, const char *str2) is used to calculate the length of the initial segment of str1, which consists entirely of characters not in str2.

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.