





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: PRBLM SOLVNG:COMPUTR; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Spring 2009;
Typology: Study notes
1 / 9
This page cannot be seen from the preview
Don't miss anything!






CSCE150A
Modularization Methods to Help Examples
Lecture 06 – Modular Programming
Derrick Stolee
Spring 2009
1 / 9^ [email protected]
CSCE150A
Modularization Methods to Help Examples
Big programs get BIG. Most software is many millions of lines of code. Organization is important
CSCE150A
Modularization Methods to Help Examples
Usually, functions have a single return value. This is the only way to tell the “caller” any information* Parameters are pass by value, that is: values are copied. Consider the following definition: int func(int a) { a = 5; return 0; } What happens with the following code in main(): int b=1; int c = func(b);
CSCE150A
Modularization Methods to Help Examples
We can pass values back to the caller more than just return! A parameter given by “type * name” is called a pointer. This is called pass by reference. We can set pointer values using (*name) = We pass an address to the function in the call using &variable. (see drawing on board)
CSCE150A
Modularization Methods to Help Examples
See code sample ch6sam2.c The buyCoffee method returns the charge. Updates the total amount of coffee purchased (numCups) Checks for a coupon, or adds a coupon depending on number of cups.
CSCE150A
Modularization Methods to Help Examples
See code sample ch6sam3.c The swapper method swaps the values if out of order. A sequence of calls to swapper sorts five variable values.