What will be the output of the following C# code?
static void main(string[] args)
{
int []arr = new int[]{ 1, 2, 3, 4, 5};
fun (ref arr);
for (int i = 0; i < arr.Length ; i++)
Console.WriteLine( arr[i] + ” “);
}
static void fun(ref int[]a)
{
a = new int[6];
a[3] = 32;
a[1] = 24;
}
a) 0, 0, 32, 0, 0, 0
b) 0, 24, 0, 32, 0, 0
c) 24, 0, 32, 0, 0, 0
d) 0, 0, 32, 0, 0, 0
Answer: b
Explanation: index positions which are assigned the new values are passed as a reference parameter and hence rest positions are filled with zero values.
Output :
0 24 0 32 0 0
Related Posts
What is the output of the given code?
counter=1
if counter<=5
puts (counter)
counter=counter+1What is the output of the given code?
if(a==10 && b=9)
print “true”
else
print “false”
endWhich of the following are used for comparison?
What is the output of the given code?
a=10
b=9
if(a>b)
print (“a greater than b”)
else
print “Not greater”
endAssignment operator is also known as relational operator.
What is the output of the given code?
a=”string”
b=”strings”
if(a==b)
print (“a and b are same”)
else
print “Not same”
endWhat is the output of the given code?
test_1 = 17 > 16
puts(test_1)
test_2 = 21 <= 30
puts(test_2)
test_3 = 9 >= 9
puts(test_3)
test_4 = -11 > 4
puts(test_4)
Join The Discussion