Exercise: Strings

Questions for: Strings

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
Answer: B
No answer description is available. Let's discuss.
Which of the following statements are true about the C#.NET code snippet given below?
String s1, s2; 
s1 = "Hi"; 
s2 = "Hi";
  1. String objects cannot be created without using new.
  2. Only one object will get created.
  3. s1 and s2 both will refer to the same object.
  4. Two objects will get created, one pointed to by s1 and another pointed to by s2.
  5. s1 and s2 are references to the same object.
A:
1, 2, 4
B:
2, 3, 5
C:
3, 4
D:
2, 5
Answer: B
No answer description is available. Let's discuss.
Is there any difference between the two statements?
char *ch = "ExamAdept";
char ch[] = "ExamAdept";
A:
Yes
B:
No
C:
D:
Answer: A
In first statement the character pointer ch stores the address of the string "ExamAdept".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.
For the following statements will arr[3] and ptr[3] fetch the same character?
char arr[] = "ExamAdept";
char *ptr = "ExamAdept";
A:
Yes
B:
No
C:
D:
Answer: A

Yes, both the statements prints the same character 'i'.

Will the program compile successfully?
#include<stdio.h>

int main()
{
    char a[] = "India";
    char *p = "BIX";
    a = "BIX";
    p = "India";
    printf("%s %s\n", a, p);
    return 0;
}
A:
Yes
B:
No
C:
D:
Answer: B
Because we can assign a new string to a pointer but not to an array a.
Ad Slot (Above Pagination)
Quiz