I'm a student just starting to learn Programming for C++. We've recently gone over a term called "Pass-by value" in our lectures and I'm a little confused about what it means and what it's meant do. I've asked my professor and even looked over my materials multiple times, but I just can't get it. I understand that it stop the argument from being changed, and it mainly uses the 'void' header, but that is about it. Could anyone go into further detail about this? It would help tremendously.
Asked
Active
Viewed 34 times
1
-
1It short, it means that if you don't put &, the instance will be copied. So if you assign in the function, the value at caller side doesn't get updated. I guess this is a duplicate question – JVApen Apr 09 '20 at 06:36
-
1Unrelated, but maybe you have a little misunderstanding about "the 'void' header" - You probably mean the return type? For example in `void foo(int x)`, the _return type_ is `void`. What the function returns, doesn't matter for the question at hand, you have to look at the function parameters. In this case it's `int x`, meaning an `int` passed by value. – Lukas-T Apr 09 '20 at 06:48