Explain the difference between passing parameters by value and passing parameters by reference with an example?



Explain the difference between passing parameters by value and passing parameters by reference with ..

Answer / Kum Anshu Gupta

Passing by value means a copy of the variable is passed to the function. If the variable is modified within the function, the original variable remains unchanged.nnPassing by reference means the address of the variable is passed to the function. Any changes made in the function affect the original variable.nnHere's an example:n```csharpnvoid SwapValuesByValue(int a, int b) {n int temp = a;n a = b;n b = temp;n }nvoid SwapValuesByReference(ref int a, ref int b) {n int temp = a;n a = b;n b = temp;n }nint x = 10;nint y = 20;nSwapValuesByValue(x, y);nConsole.WriteLine("x: " + x + " y: " + y);nSwapValuesByReference(ref x, ref y);nConsole.WriteLine("x: " + x + " y: " + y)n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

How do you set a class path?

1 Answers  


When you inherit a protected class-level variable, who is it available to?

4 Answers   Visual Soft,


How do I run a cshtml file?

1 Answers  


What is the difference between “constant” and “readonly” variables in c#?

1 Answers  


What are constants in c#?

1 Answers  


What is the difference between do and while loop?

1 Answers  


What is the purpose of a console table?

1 Answers  


What is ilasm.exe used for?

1 Answers  


In .NET which is the smallest unit of execution?

1 Answers   Siebel,


Explain about WSDL

1 Answers   Digital GlobalSoft,


what is accessspecifier and explation each with example?

3 Answers  


What is difference between array and list in c#?

1 Answers  


Categories