CS31-4

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

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

View Full Document Right Arrow Icon
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-1 CS 31 : Introduction to Computer Science I Topic 4 Parameters and Overloading
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-2 Parameters Function Parameters Provide data for functions Can provide a way to return values Placeholders for arguments in calls
Background image of page 2
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-3 Parameters Function Parameter Types Two Different Types Call-by-value parameters Call-by-reference parameters
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-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
Background image of page 4
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-5 Parameters Call-By-Value Example void v(int p1, bool p2, float p3) { p1 = 4; p2 = false; p3 = 19.8; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-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; }
Background image of page 6
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-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
Background image of page 7

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

View Full DocumentRight Arrow Icon
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-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
Background image of page 8
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-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
Background image of page 9

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

View Full DocumentRight Arrow Icon
CS 31: Introduction To CS I Topic 4: 1/2009 John A. Rohr All Rights Reserved JAR 4-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
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 41

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

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

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