c++ ##_##
1) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
Console.WriteLine(ARR.GetLength(1));
}
Answer & Explanation
Correct answer: 4
Runtime Error
The above code will generate runtime exception.
2) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
Console.WriteLine(ARR.GetLength(0));
}
Answer & Explanation
Correct answer: 1
5
The above code will print length of created array.
3) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
Console.WriteLine(ARR.MAX());
}
Answer & Explanation
Correct answer: 3
Syntax Error
The above code will generate syntax error, because MAX() method is not available.
4) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
int X = 0;
int i = 0;
X = ARR[0];
for (i = 1; i < ARR.Length; i++)
{
if (X < ARR[i])
X = ARR[i];
}
Console.WriteLine(X);
}
Answer & Explanation
Correct answer: 1
5
The above code will print greatest value of array.
5) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[,] ARR = {{1,2},{3,4}};
Console.WriteLine(ARR.GetLength(1));
}
Answer & Explanation
Correct answer: 2
2
The GetLength(1) method will print specified number of elements in the dimensions.
翻译自: https://www.includehelp.com/dot-net/csharp-arrays-aptitude-questions-and-answers-4.aspx
c++ ##_##