C# Programming - Functions and Subroutines - Discussion
Discussion Forum : Functions and Subroutines - General Questions (Q.No. 2)
2.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class SampleProgram
{
static void Main(string[] args)
{
int[]arr = newint[]{ 1, 2, 3, 4, 5 };
fun(ref arr);
}
static void fun(ref int[] a)
{
for (int i = 0; i < a.Length; i++)
{
a[i] = a[i] * 5;
Console.Write(a[ i ] + " ");
}
}
}
}
Discussion:
4 comments Page 1 of 1.
JustQ said:
1 decade ago
Arr is declared as a reference once variable a is declared it inherits what arr was meaning the array. The array length is 5 stepping through the array with the index multiplies each number within the array by 5 giving a pattern of 5, 10, 15, 20, 25.
Emad said:
1 decade ago
Please can you tell me this program function in detail I can't understand?
Ibrahim said:
1 decade ago
@Ted S.
Then it will miss to assign last value o the last member of array.
Then it will miss to assign last value o the last member of array.
Ted S said:
1 decade ago
Should the "for" loop not be "for (int i = 0; i < a.Length - 1; i++) { ... }"?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers