{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS31-5

CS31-5 - CS 31 Introduction to Computer Science I Topic 5...

This preview shows pages 1–12. Sign up to view the full content.

CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-1 CS 31 : Introduction to Computer Science I Topic 5 Parameters and Overloading

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

View Full Document
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-2 Parameters Function Parameters Provide data for functions Can provide a way to return values Placeholders for arguments in calls
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-3 Parameters Function Parameter Types Two Different Types Call-by-value parameters Call-by-reference parameters

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

View Full Document
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-4 Parameters Call-By-Value Parameters Input only: Expression (or variable) Actually local variables in the function Exist during execution of the function Initialized to value of argument on call Can be changed inside function Existence ends at function return
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-5 Parameters Call-By-Value Example void v(int p1, bool p2, float p3) { p1 = 4; p2 = false; p3 = 19.8; }

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

View Full Document
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-6 Parameters Call-By-Value Example int main() { void v(int p1, bool p2, float p3); int a1 = 24; bool a2 = true; float a3 = 80.4; v(a1, a2, a3); return 0; }
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-7 Parameters Call-By-Value Example Arguments are copied to parameters Parameters are local variables in called Calling Function 24 true 80.4 int: a1 bool: a2 float: a3 Called Function 24 true 80.4 int: p1 bool: p2 float: p3 At Entry

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

View Full Document
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-8 Parameters Call-By-Value Example Arguments are copied to parameters Parameters are local variables in called Calling Function 24 true 80.4 int: a1 bool: a2 float: a3 Called Function 4 false 19.8 int: p1 bool: p2 float: p3 At Return
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-9 Parameters Call-By-Reference Parameters Can be used for input and output Must be a variable only: no expressions Use actual variables in the calling function Exist during execution of the calling function Changes in function change actual variable Existence ends at calling function return

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

View Full Document
CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 5-10 Parameters Call-By-Reference Parameters Compiler handles the details Attached to end of type name or beginning of parameter name in prototype and function definition header
Introduction To CS I 9/2009 John A. Rohr All Rights

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 41

CS31-5 - CS 31 Introduction to Computer Science I Topic 5...

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

View Full Document
Ask a homework question - tutors are online