C# Programming - Functions and Subroutines - Discussion

Discussion :: 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 ] + " "); 
            } 
        } 
    } 
}

[A]. 1 2 3 4 5
[B]. 6 7 8 9 10
[C]. 5 10 15 20 25
[D]. 5 25 125 625 3125
[E]. 6 12 18 24 30

Answer: Option C

Explanation:

No answer description available for this question.

Ted S said: (May 23, 2013)  
Should the "for" loop not be "for (int i = 0; i < a.Length - 1; i++) { ... }"?

Ibrahim said: (Oct 18, 2013)  
@Ted S.

Then it will miss to assign last value o the last member of array.

Emad said: (Dec 8, 2013)  
Please can you tell me this program function in detail I can't understand?

Justq said: (Feb 24, 2014)  
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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.