What's The difference between Call by Value and Call by Reference ?
and plz give me a clear example
thanks in advance

6 Years
Discussion Span
Last Post by Zinderin

To start with, that's a pretty solid distinction to make and should be covered in your textbook.

Adding to that, have you perhaps tried looking at online references like msdn.microsoft.com or google.com to try to find the answer prior to posting here?

I ask simply because, honestly, this looks like a homework question and not so much like any effort was put into getting the answer prior to posting it to the boards.

Best of luck with your answer though, I just woke up so I'm not about to dig into my brain for programming theory lessons to provide here :twisted:


it's Not a homework btw
just wanna understand the difference between call by value & reference !!!


Excellent :) But that still doesn't address the rest of what I said :twisted:

For example, if you were to go to Google.com and enter a quick search there you'd find that there are a number of resources right there that explain the concept(s) you're asking about. Additionally, if you look at the 3rd reference that shows up with the search I linked it is based out of the other site I mentioned... msdn.microsoft.com.

I've got no problem helping people with complex concepts or coding problems they're having but usually MY first stop when I don't know something is to check google :twisted:

Votes + Comments
totally agree :)
Indeed, Google is your friend!!

Lusiphur is correct ... in that this is something that is a programming "concept" not just a one page "here it is."

But here it is ... when you pass a variable (like int, string, bool, or an object) to another method by value, nothing done in that method is going to effect the variable you passed.

Conversely, when you pass a variable to a method by reference, then all bets are off, and your variable could be changed by the method.

That is why you MUST use the word REF when you define the method (so the method knows its not by value .... and why you have to use the REF when you call the method (so you, the programmers calling the method are well aware all bets are off).

And if you take that and just run with it, you're foolish. Because ref is a very powerful ability ... but it can also cause you so much pain if you don't know all its ins and outs. Don't be lazy or careless about REF. There's performance issues tied to the stack and the heap and code structure/protections/standards to keep in mind.

Learn when, where and why you should use ref, and why you shouldn't.

Also investigate "boxing" in C#.

Edited by Zinderin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.