Strings c programming questions

1.

Which of the following statements are true about the C#.NET code snippet given below?

String s1, s2;
s1 = “Hi”;
s2 = “Hi”;

String objects cannot be created without using new.
Only one object will get created.
s1 and s2 both will refer to the same object.
Two objects will get created, one pointed to by s1 and another pointed to by s2.
s1 and s2 are references to the same object.

A.     1, 2, 4
B.     2, 3, 5
C.     3, 4
D.     2, 5
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
2.

Which of the following will be the correct output for the C#.NET code snippet given below?

String s1 = “ALL MEN ARE CREATED EQUAL”;
String s2;
s2 = s1.Substring(12, 3);
Console.WriteLine(s2);

A.     ARE    B.     CRE
C.     CR    D.     REA
E.     CREATED
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
3.

Which of the following statements will correctly copy the contents of one string into another ?
A.

String s1 = “String”;
String s2;
s2 = s1;

B.

String s1 = “String” ;
String s2;
s2 = String.Concat(s1, s2);

C.

String s1 = “String”;
String s2;
s2 = String.Copy(s1);

D.

String s1 = “String”;
String s2;
s2 = s1.Replace();

E.

String s1 = “String”;
String s2;
s2 = s2.StringCopy(s1);

Answer & Explanation

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
4.

The string built using the String class are immutable (unchangeable), whereas, the ones built- using the StringBuilder class are mutable.
A.     True    B.     False
Answer & Explanation

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
5.

Which of the following will be the correct output for the C#.NET code snippet given below?

String s1 = “Nagpur”;
String s2;
s2 = s1.Insert(6, “Mumbai”);
Console.WriteLine(s2);

A.     NagpuMumbair
B.     Nagpur Mumbai
C.     Mumbai
D.     Nagpur
E.     NagpurMumbai
Answer & Explanation

Answer: Option E

Explanation:

No answer description available for this question.

Leave a Reply0

Your email address will not be published.