Pass by Value Vs Pass by Reference

Pass by value:

Code snippet for JavaScript:

Image for post
Image for post
Image for post
Image for post

The main aspect of pass by value is :”You cannot modify the values you pass into the function”. But you may wonder how ‘t’ got changed?
Actually if you examine carefully,’t’ never changed.The object which ‘t’ was referencing got changed.

Image for post
Image for post

Pass by Reference:

If you can modify the values passed onto a function,then it is pass by reference.

Pass by Reference in C:

Pass by Reference in C++:

Suffering from Knowledge Quest

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store