23.03.2013 Views

Arrays, parameter passing, pointers and dynamic allocation. - ELIS

Arrays, parameter passing, pointers and dynamic allocation. - ELIS

Arrays, parameter passing, pointers and dynamic allocation. - ELIS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Pass-by-reference<br />

S void myFunction(int &x);<br />

S x is a reference to an int.<br />

S Be careful – you are giving callee method power to change<br />

your variable<br />

S To save copying space, but protect your variable, use const<br />

S void myFunction(const int &x);<br />

S Now myFunction cannot modify x.<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!