This set of Arduino Multiple Choice Questions & Answers (MCQs) focuses on “String Manipulation”.
1. What is the special escape sequence for newline in C++?
a) ‘\b’
b) ‘\m’
c) ‘\n’
d) ‘\\’
View Answer
Explanation: The newline character is used for shifting the cursor to the next line for any output to the monitor. It is mostly used for formatting output. During execution this escape sequence is converted to the OS Specific newline representation.
2. What is the minimum number of arguments that the strcpy() function accept?
a) 4
b) 3
c) 2
d) 1
View Answer
Explanation: The strcpy() function is used to copy the contents from one String variable to another. Hence it requires a minimum of two arguments that include the source variable (The variable from whose contents need to be copied from) and the destination variable (The variable to which the contents are to be copied to).
3. What is the function of the strcmp() function?
a) To compare two strings
b) To compile two strings
c) To concatenate two strings
d) To converge two strings
View Answer
Explanation: The strcmp() function takes in two arguments to work and it’s job is to compare two strings. it returns 0 if the first and second strings are the same, returns a number greater than 0 if the first string is greater than the second one and vice versa.
4. Which of the following escape sequences placed at the end of a string makes the string a Null Terminated String?
a) ‘\p’
b) ‘\u’
c) ‘\0’
d) ‘\1’
View Answer
Explanation: The ‘\0’ when placed at the end of a string makes it a null terminated string which is simply a single dimensional array of characters that are trailed by the ‘\0’ escape sequence. It is also called the ASCII NUL character.
5. What is the return type of the front() function?
a) char
b) int
c) long
d) short
View Answer
Explanation: The front() function returns a character from the string given as input. It takes in no arguments. It returns the first character that is present in the string. It can be used as “cout<<str.front();” which prints the first character from the variable “str”.
6. How many arguments does the back() function take?
a) 0
b) 1
c) 2
d) 3
View Answer
Explanation: The back() function returns a character from the string given as input. It takes in no arguments. It returns the last character that is present in the string. It can be used as “cout<<str.front();” which prints the last character from the variable “str”.
7. How many arguments does the at() function take?
a) 0
b) 1
c) 2
d) 3
View Answer
Explanation: The at() function returns a character from the string given as input. It takes 1 argument. It returns the character that is present in the string as specified by the argument. It can be used as “cout<<str.at(1);” which prints the second character from the variable “str”.
8. Which of these functions are used to partially or fully substitute a string?
a) replace()
b) size()
c) subs()
d) substring()
View Answer
Explanation: The replace function works with 3 arguments; the index in the source string, the string to be substituted with, and the string variable. It can be used as “str.replace(a,b, “hello”);” where ‘b’ characters are replaced from index ‘a’ in ‘str’.
9. What is the return type of the substr() function?
a) int
b) long
c) byte
d) string
View Answer
Explanation: The substr() function is used to return a portion of a given string. It accepts 2 inputs as arguments; the lower and upper indexes. It can be used as “str.substr(a,b);” where a is the lower index and b is the upper index.
10. Is there any difference between the usage of the size() and the length() function?
a) Yes
b) No
View Answer
Explanation: The size() and length() functions both return the number of characters that constitute the string given and can be used interchangeably from a utilitarian standpoint. There is absolutely no difference between the two functions.
Sanfoundry Global Education & Learning Series – Arduino.
To practice all areas of Arduino, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Electrical Engineering Books
- Practice Electrical & Electronics Engineering MCQs
- Check Arduino Books
- Apply for Electrical Engineering Internship
- Apply for Electrical & Electronics Engineering Internship