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.
1. Which among the following is Copying function?
a) memcpy()
b) strcopy()
c) memcopy()
d) strxcpy()
View Answer
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
Explanation: The strcat() function is used for concatenating two strings, appends a copy of the string.
char *strcat(char *s1,const char *s2);
3. The ______ function appends not more than n characters.
a) strcat()
b) strcon()
c) strncat()
d) memcat()
View Answer
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
Explanation: The strcmp() function compares the string s1 to the string s2.
int strcmp(const char *s1,const char *s2);
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
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
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.
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
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
Explanation: NULL macro is the value of a null pointer constant.
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
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
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.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Check C Books
- Check Computer Science Books
- Watch Advanced C Programming Videos