| 1. | Which of the following function is correct that finds the length of a string? |
|||||||
Answer: Option A Explanation: Option A is the correct function to find the length of given string. Example:
Output: Length = 8 |
| 2. | Which of the following function is more appropriate for reading in a multi-word string? |
|||||||
Answer: Option C Explanation: gets(); collects a string of characters terminated by a new line from the standard input stream stdin
Output: Enter a string: IndiaBIX The string input was: IndiaBIX |
| 3. | Which of the following function is used to find the first occurrence of a given string in another string? |
|||||||
Answer: Option C Explanation: The function strstr() Finds the first occurrence of a substring in another string Declaration: char *strstr(const char *s1, const char *s2); Return Value: Example:
Output: The substring is: iaBIX |
| 4. | The library function used to find the last occurrence of a character in a string is |
|||||||
Answer: Option C Explanation: Declaration: char *strrchr(const char *s, int c); It scans a string s in the reverse direction, looking for a specific character c. Example:
Output: The position of 'i' is: 19 |
| 5. | How will you print \n on the screen? |
|||||||
Answer: Option D Explanation: The statement printf("\\n"); prints '\n' on the screen. |
| 6. | If the two strings are identical, then strcmp() function returns |
|||||||
Answer: Option C Explanation: Declaration: strcmp(const char *s1, const char*s2); The strcmp return an int value that is if s1 < s2 returns a value < 0 if s1 == s2 returns 0 if s1 > s2 returns a value > 0 |
| 7. | Which of the following function sets first n characters of a string to a given character? |
|||||||
Answer: Option B Explanation:
Declaration: char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch
Output: string before strnset: abcdefghijklmnopqrstuvwxyz string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz |
