4.3.1 - Introduction to Strings and its Functions ( Strcat(),Strlen(),Strcmp() etc).
1. What does the null character "\0" represent in a string in C?
Correct Answer: (B) The end of the string
2. Which function is used to find the length of a string in C?
Correct Answer: (A) strlen()
3. What is the return value of the strlen() function when applied to an empty string?
Correct Answer: (C) 0
4. Which function is used to copy one string to another in C?
Correct Answer: (B) strcpy()
5. Which function is used to concatenate two strings in C?
Correct Answer: (C) strcat()
6. What is the return value of strcmp() if two strings are identical?
Correct Answer: (A) 0
7. Which header file is required for using string functions like strlen(), strcpy(), and strcmp()?
Correct Answer: (C) string.h
8. If char s1[] = "hello"; and char s2[] = "world";, what does strcat(s1, s2); do?
Correct Answer: (B) Combines the two strings and stores them in s1
9. Which of the following string functions compares two strings lexicographically?
Correct Answer: (C) strcmp()
10. If char s1[] = "abc"; and char s2[] = "ABC";, what does strcmp(s1, s2); return?
Correct Answer: (C) Negative integer
11. Which function can be used to safely copy a specified number of characters from one string to another?
Correct Answer: (A) strncpy()
12. What does the strcmp() function return if the first string is lexicographically smaller than the second?
Correct Answer: (D) A negative integer
13. What will strlen("hello world") return?
Correct Answer: (B) 11
14. Which of the following strings will be stored correctly in memory?
Correct Answer: (D) Both (A) and (B)
15. Which function can be used to append a specific number of characters from one string to another?
Correct Answer: (A) strncat()
16. What does strcpy() do with the null terminator \0 when copying a string?
Correct Answer: (B) Copies it
17. What is the output of strcmp("apple", "banana")?
Correct Answer: (C) Negative integer
18. In C, strings are stored as arrays of characters terminated by which character?
Correct Answer: (B) '\0'
19. Which of the following functions is not used for string comparison?
Correct Answer: (C) strcpy()
20. What will the function strcmp("apple", "apple") return?
Correct Answer: (C) 0