8.6: Pass by Value vs. Pass by Reference – Processing Tutorial


This video covers passing arguments into a function and what happens when you pass an object vs. a primitive value.

Book: Learning Processing A Beginner’s Guide to Programming, Images,Animation, and Interaction

Chapter: 8

Official book website:

annotations added: click here to subscribe

Help us caption & translate this video!

? Code of Conduct:



  1. When I play around with this concept it doesn't seem to apply to String or BigInteger…could someone explain why?

  2. Man, you explained something , that im struggling to get for weeks, just in 7 mins, and i got it completely.

    Thank you very much u have a talent to teach!

  3. Thanks for brilliant explanation! But there is something I can't understand.
    6:30 if fill(col); is under ellipse(x,y,r*2,r*2); the particle that changes color will be p1 rather than p2.
    I can't figure out why..

  4. How is this correct? I mean I've tested with String, Integer and an object I've created and still have not have not the same results, it is always pass by value with what I've tested. The argument object does not change, once the called method is finished. I have not yet seen any pass by reference in Java.

  5. C# (Because it is a far superior language) is pass by value always by default. You can pass by reference by using the "ref" keyword in the parameter declaration and also when calling the function.
    change(ref x);
    static void change(ref int x){}

  6. How does x become val in the first bit of code? It just says x = 50 and the method uses int val but nowhere does x become val in any way?

  7. Thank you for this video. I didn't know what Pass by Reference meant before watching it to be honest. Apple's programming language, Swift, uses this a lot when dealing with UnsafeMutableRawPointers which makes sense. It makes me wonder if referencing and using the & operator actually causes less crashes than using other passing methods.

  8. finally, this made sense, not the part where you were overlapping circles but the first part was perfect, I finally understand this concept. Thank you!

  9. I know you got lots of hate about Java stuff BUT you helped me understand the passing by reference stuff that I needed for C++ so thank you! 🙂

  10. I've been trying to understand this for years…now I think I've got it.

    You input a value (50 in this vid) into a function.
    You want to do some operations on that value to obtain a result.
    …but the result of the operation (100) is stored in a separate variable call val.
    …and since anything in a function is local, only the input values (50) and the return value can be seen by the rest of the program. You want the return value, not the original input value. So you to pass the result back to the main program.

    Why couldn't you could just say "return val;"?

  11. Umm…I know it's been 3 years since this video but, could we continue this in depth Java tutorial please? Or are there other videos on the channel I am not seeing? You are a great teacher and I'm currently learning from codecademy and this is a great supplement to that.

  12. Javascript is always pass by value. Pass by reference does not exist in JavaScript. When you remind yourself about the fact that an object and a reference to that object are 2 independent things, it will make more sense. I suppose we've been conflating and object "reference" and passing function arguments "by reference."

    When passing a value, the value of that reference (e.g. the address of the object) is copied and that copy is passed – This is the definition of pass by value. "Pass by reference" means the original reference, not a copy, is passed. Here's the litmus test: In the called function assign a different object to the reference variable. If the original reference now points to this different object then you have pass by reference. But this does not happen in JavaScript.

    Of course you can change the object's properties, because the reference copy is pointing to the same object. But that is not germane. Rather, "Pass by xxxx" means – whatever you're passing, if it a copy it is "by value", if it is the original it is "by reference".

  13. I got it but I think you could make it better by using a much simpler method. Print one attribute value of the object. Pass the object to a method, and just do one thing to one attribute of that object and then print it again. Return from the method and print that attribute once more to show that the change is permanent..


Please enter your comment!
Please enter your name here