CMPSC 16 Lecture Notes - Lecture 9: Ampersand, Local Variable, Positional Notation

63 views3 pages
26 Oct 2016
School
Course
Professor

Document Summary

When you call a function, your arguments are getting passed on as values: what (cid:449)e"(cid:448)e been doing so far, the call func(a,b) passes on the values of a and b. You can also call a function with your arguments used as references to the actual variable location in memory. Allows us to change the variable used in the function call. Arguments for call-by-reference parameters must be variables, not numbers. We use the ampersand symbol & to distinguish a variable as being call-by-reference in a function definition. Call-by-reference works almost as if the argument variable itself is substituted for the formal para(cid:373)eter, (cid:374)ot the argu(cid:373)e(cid:374)t"s (cid:448)alue. Call-by-value and call-by-reference parameters can be mixed in the same function. Does the function need to change the value of the variable used as an argument: yes use cbr formal parameter, no use cbv formal parameter. Forgetting the ampersand (&) creates a cbv parameter: the value of the variable will not be changed.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents