Reference parameters to functions

Reference parameters to functions - Referenceparametersto...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Reference parameters to  functions things keep on changing
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem sometimes a function MUST return more  than ONE value (or it would be more  convenient if it could) you cannot use "return a,b;" - a function  can only return one thing what other return channel is there?  the parameter list!
Background image of page 2
Until now parameters have been passed "by  value" means they have been COPIED INTO the  memory of the function when it started  running  nothing done to the copy of the  parameter  was permanently changing the  corresponding argument "by value" is done for safety's sake  can't accidentally change the parameter
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Now a change is needed A function can pass a parameter so that  it CAN permanently change the  corresponding argument it's called "passing by reference" in front of the identifier in parameter lists  (in function headers and prototypes),  NOT in the call!
Background image of page 4
Example Write a function that can input some  numbers and return their sum and 
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/13/2011 for the course CS 115 taught by Professor Staff during the Fall '08 term at Kentucky.

Page1 / 15

Reference parameters to functions - Referenceparametersto...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online