L09_functions_reference

L09_functions_reference - EECS 183 University of Michigan...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: EECS 183 University of Michigan Pass by Reference Mary Lou Dorf Functions: Pass By Reference Functions: Pass By Reference EECS 183 University of Michigan Pass by Reference Mary Lou Dorf Pass by Reference Pass by Reference • You may want more than one value back from a function • Solution: pass them through the parameter list – Ex: void functionName (int & param1, int & param2); – ‘ & ’ means the address of the variable is passed – Can modify variables directly EECS 183 University of Michigan Pass by Reference Mary Lou Dorf Example: swap Example: swap Let x = -2 and y = 5 Say we want to swap x and y so that x = 5 and y = -2 How do we do it? … EECS 183 University of Michigan Pass by Reference Mary Lou Dorf Example: swap Example: swap #include <iostream> using namespace std; void swap (int& a, int& b); int main ( ) { int x = -2, y = 5; swap (x,y) cout << “x = ” << x << “y = “ << y << endl; return (0); } How would you code swap? EECS 183 University of Michigan Pass by Reference...
View Full Document

This note was uploaded on 02/12/2010 for the course EECS 183 taught by Professor Dorf during the Fall '08 term at University of Michigan.

Page1 / 15

L09_functions_reference - EECS 183 University of Michigan...

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