Parameters

Parameters - Parameters Dr. David Gaitros LEARNING...

Info iconThis preview shows pages 1–7. 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: Parameters Dr. David Gaitros LEARNING OBJECTIVES Parameters Call-by-value Call-by-reference Mixed parameter-lists Overloading and Default Arguments Examples, Rules Testing and Debugging Functions assert Macro Stubs, Drivers 4-2 PARAMETERS Two methods of passing arguments as parameters Call-by-value "copy" of value is passed Changing the copy does not affect the original Safest thing to do and should be the most common Call-by-reference "address of" actual argument is passed Change to the parameter changes to the original More difficult to do and more dangerous 4-3 CALL-BY-VALUE PARAMETERS Copy of actual argument passed Considered "local variable" inside function If modified, only "local copy" changes Function has no access to "actual argument" from caller This is the default method Used in all examples thus far 4-4 #include <iostream> using namespace std; // Example of call by value // X contains a copy of the original value void Plusit(int x) { x = x+x; } int main(void) { int y=4; Plusit(y); cout << y << endl; // The output will be 4 because // Inside the routine only the local // copy was changed. return 0; } 4-5 C o p y r i g h t © 2 1 1 D r . D a v i d G a i t r o s , F l o r i d a S t a t e U n i v e r s i t y . CALL-BY-VALUE PITFALL Common Mistake: Declaring parameter "again" inside function: double fee(int hoursWorked, int...
View Full Document

This note was uploaded on 11/07/2011 for the course COP 3014 taught by Professor Tyson during the Fall '10 term at FSU.

Page1 / 17

Parameters - Parameters Dr. David Gaitros LEARNING...

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

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