ProgrammingSequence, selection, iteration, procedures, functions, modules, parameters, compilers, interpreters

Syllabus Detail

  • Scope and lifetime of identifiers with parameter passing: value and ref. 12 ATAR

Background

  • Parameter passing is the technique of passing values between functions or subroutines
  • Two common methods of passing exist; value passing and reference passing
  • A parameter's scope is the boundary of which a value can exist in
  • The lifetime of an identifier is dependent on the type of passing being performed

 

Value Passing

  • A parameter called by value simply outputs the value of the actual parameter
  • Passing by value is essentially passing a copy of the original value to function or submodule
  • If the value of the original parameter were to change, our copy would not reflect this change (because the value we were given initially is the only copy we have)

 

Reference Passing

  • A parameter passed by reference refers to the original location of the parameter's value
  • This means that any changes to this value will be reflected to our own value (because our value is really just a "link" to the original value)
  • Reference passing can be thought of as "symbolic linking" between a parameter's value and the calling submodule or function

 

The "Web Page" Example

  • If we were to print out a copy of this web page and handed one to each student, this would be an example of value passing
    This is because the original copy of the website remains unchanged - if we were to destroy the printout of our website or make annotations and notes, these changes wouldn't be reflected on the original copy. This is an example of passing by value.
  • If we were to send a copy of the URL to each student, this would be an example of reference passing
    Any changes that were made to the web page would be reflected on both the original and the given link to the website. In the same notion, if we were to delete the URL pointing to the website, the actual contents (or value) of the website would remain unchanged, because we're only deleting a reference (link) to that page.

 

Further Research

 

Worksheet and Practice (yet to be added)

Found an error or have an enhancement? Please let us know via this contact form