0% found this document useful (0 votes)
5 views3 pages

String MCQ Questions

The document consists of a series of questions and answers related to string manipulation in C++. It covers topics such as string declaration, length, concatenation, comparison, and various functions associated with strings. The answers indicate that C++ strings are mutable and can be manipulated using multiple functions and operators.

Uploaded by

sksafi5289
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

String MCQ Questions

The document consists of a series of questions and answers related to string manipulation in C++. It covers topics such as string declaration, length, concatenation, comparison, and various functions associated with strings. The answers indicate that C++ strings are mutable and can be manipulated using multiple functions and operators.

Uploaded by

sksafi5289
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1: What is the correct way to declare a string in C++?

- string s;
- String s;
- char s[];
- All of the above
Answer: All of the above

Q2: Which function is used to find the length of a string in C++?


- length()
- size()
- strlen()
- Both length() and size()
Answer: Both length() and size()

Q3: What is the index of the last character in a string of length n?


- n
- n-1
- 0
- n+1
Answer: n-1

Q4: Which function is used to concatenate two strings in C++?


- append()
- concat()
- combine()
- merge()
Answer: append()

Q5: Which header file is required for using string in C++?


- <string>
- <cstring>
- <iostream>
- <stdlib.h>
Answer: <string>

Q6: How to compare two strings in C++?


- == operator
- compare()
- Both
- None
Answer: Both

Q7: Which function is used to extract a substring in C++?


- substring()
- substr()
- slice()
- cut()
Answer: substr()

Q8: How to access the first character of a string in C++?


- str[0]
- str.at(0)
- *str
- All of the above
Answer: All of the above

Q9: What does the empty() function do in string class?


- Returns true if string is empty
- Returns string size
- Clears the string
- Adds a null character
Answer: Returns true if string is empty

Q10: Which function is used to erase part of a string in C++?


- erase()
- remove()
- clear()
- cut()
Answer: erase()

Q11: What is the output of this code: string s = "Hello"; cout << s[1];
- H
- e
- l
- o
Answer: e

Q12: What does the clear() function do in string class?


- Deletes the string
- Sets string to empty
- Reverses the string
- None
Answer: Sets string to empty

Q13: Which function returns the position of the first occurrence of a substring?
- find()
- indexOf()
- search()
- match()
Answer: find()

Q14: What is the return type of the compare() function in C++ string?
- bool
- int
- string
- void
Answer: int

Q15: How can you get the last character of a string s in C++?
- s[s.length()-1]
- s.back()
- s.at(s.size()-1)
- All of the above
Answer: All of the above

Q16: Which function is used to insert characters into a string?


- insert()
- put()
- place()
- copy()
Answer: insert()

Q17: What does the string::npos constant represent?


- Maximum size of a string
- End of the string
- No position found
- Start of the string
Answer: No position found
Q18: What happens if you access out-of-bounds index in string using at()?
- Returns null
- Returns garbage
- Throws an exception
- Ignores it
Answer: Throws an exception

Q19: Which function is used to replace part of a string in C++?


- replace()
- overwrite()
- substitute()
- fill()
Answer: replace()

Q20: Which of the following is true about strings in C++?


- They are mutable
- They can be compared using == operator
- They can be concatenated using +
- All of the above
Answer: All of the above

You might also like