Strings Questions
Practice Strings MCQs with answers and explanations. Page 1 of 3.
Category
C# Programming
Topic
Strings
Page
1 / 3
Mode
Practice
Questions
Open any question to view the answer and explanation.
In the C standard library, which function finds the first occurrence of a given substring within another string (i.e., searches for one string inside a larger string)?
Open
View answer
In C, how would you print the two literal characters backslash and n (i.e., the text '
') on the screen using printf?
Open
View answer
Which C library function returns a pointer to the last occurrence of a specified character within a null-terminated string?
Open
View answer
Which function sets the first n characters of a C string to a specified character (use the best match among the listed options)?
Open
View answer
For two strings s1 and s2 in C, what does strcmp(s1, s2) return if the strings are identical in content and length?
Open
View answer
Which of the following function is correct that finds the length of a string?
Open
View answer
In C input/output programming, which standard library function is most appropriate for reading a multi-word string that includes spaces from standard input?
Open
View answer
C#.NET strings: What will be printed by the following code when comparing two differently cased strings?
String s1 = 'Five Star';
String s2 = 'FIVE STAR';
int c;
c = s1.CompareTo(s2);
Console.WriteLine(c);
Choose the correct result of the call to CompareTo (case-sensitive, culture-aware comparison).
Open
View answer
C#.NET string interning and object references: consider the code
String s1, s2;
s1 = 'Hi';
s2 = 'Hi';
Which statements about object creation and references are true?
Open
View answer
C#.NET String.Insert: determine the output of
String s1 = 'Nagpur';
String s2;
s2 = s1.Insert(6, 'Mumbai');
Console.WriteLine(s2);
What is printed?
Open
View answer
C#.NET: Correct ways to convert a String to an int (assume s = '123'). Select all valid C# approaches.
Open
View answer
C#.NET strings: What is the correct way to compare two string variables s1 and s2 for equality of contents (not assignment)?
Open
View answer
C#.NET strings vs. StringBuilder: choose the correct statement about mutability and immutability.
Open
View answer
Where are C#.NET String objects created? Choose the correct statement about the memory location of a String.
Open
View answer
String and StringBuilder in C#.NET: select the correct statements.
1) Two strings can be concatenated using s3 = s1 + s2;
2) String is a primitive in C#.NET.
3) A string built with StringBuilder is mutable.
4) A string built with String is immutable.
5) Two strings can be concatenated using s3 = s1 & s2;
Open
View answer
Comparing string contents in C#.NET: which of the following are valid ways to determine if two strings s1 and s2 have equal contents?
1) if(s1 = s2)
2) if(s1 == s2)
3) int c; c = s1.CompareTo(s2);
4) if(strcmp(s1, s2))
5) if (s1 is s2)
Open
View answer
Copying the contents of one string to another in C#.NET: choose the statement that correctly creates a new string with the same contents as an existing one.
Open
View answer
C#.NET — What does this program print?
namespace CuriousTabConsoleApplication
{
class SampleProgram
{
static void Main(string[] args)
{
string str = "Hello World!";
Console.WriteLine(String.Compare(str, "Hello World?").GetType());
}
}
}
Predict the exact console output when the program runs.
Open
View answer
C#.NET — Which is the correct way to find the index of the second 's' in the string:
"She sells sea shells on the sea-shore"?
Choose the valid code snippet that correctly identifies the second occurrence.
Open
View answer
C#.NET strings — identify the correct statements about string type, literals, equality, bounds, and mutability.
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.