Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example.

Similar presentations


Presentation on theme: "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example."— Presentation transcript:

1 March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example Calling Functions from FunctionsCalling Functions from Functions Functions and Array ArgumentsFunctions and Array Arguments Lab 11Lab 11

2 March 2005 2R. Smith - University of St Thomas - Minnesota What did I do to Lab 7? How did ‘Main’ get simpler?How did ‘Main’ get simpler? How did I pass data to the functions?How did I pass data to the functions? How did I retrieve data from functions?How did I retrieve data from functions? How did I eliminate variables?How did I eliminate variables?

3 March 2005 3R. Smith - University of St Thomas - Minnesota Functions: How they work Calling vs CalledCalling vs Called –The calling function: the one that contains a function call –The called function: the statements that define that function When we call a function:When we call a function: –Our program collects up the “parameter” variables –It makes a copy of each parameter’s value –It remembers where the calling function has left off –It starts running the called function When our function is calledWhen our function is called –We get a copy of the parameter values –We create new variables to match the declarations –We perform our statements –We return to the calling function at the end: just where it left off

4 March 2005 4R. Smith - University of St Thomas - Minnesota Calling Functions from Functions The bottom line: of course it worksThe bottom line: of course it works –“Main” is a function and it calls other functions –If we write our own functions, they can also call functions How does it work?How does it work? –The computer has a “stack” –The stack contains the working data when we run a function Working dataWorking data –Where the calling function left off: which statement to return to when the called function is finished –List of parameters passed to the called function –Variables declared in the called function Recursion: a “trick” we can play with thisRecursion: a “trick” we can play with this

5 March 2005 5R. Smith - University of St Thomas - Minnesota The role of RAM RAM has a special layout to make all this workRAM has a special layout to make all this work –Space for the instructions: the statements –Space for predefined “global” RAM (we don’t use this) –Space for “dynamic” RAM (we don’t use this, either) –Space for the “Stack”

6 March 2005 6R. Smith - University of St Thomas - Minnesota How do we pass arrays? What does the function get when we pass an array?What does the function get when we pass an array? How do we signal the size of an array?How do we signal the size of an array? –How do we deal with ‘variable length’ arrays? –How do we mark the end of an array of chars (a string)? –How do indicate the number of elements in other arrays?

7 March 2005 7R. Smith - University of St Thomas - Minnesota How do we pass arrays? The function gets the array’s location in RAMThe function gets the array’s location in RAM The array must indicate its end somehowThe array must indicate its end somehow –Option: provide second parameter with the array size –Option: put a ‘sentinel’ at the end of the array, like in strings

8 March 2005 8R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example."

Similar presentations


Ads by Google