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
Parameters Dr. David Gaitros
Background image of page 1

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

View Full DocumentRight Arrow Icon
L EARNING O BJECTIVES 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
Background image of page 2
P ARAMETERS 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
C ALL - BY -V ALUE P ARAMETERS 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
Background image of page 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 Copyright © 2011 Dr. David Gaitros, Florida State University .
Background image of page 5

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

View Full DocumentRight Arrow Icon
C ALL - BY -V ALUE P ITFALL Common Mistake: Declaring parameter "again" inside function: double fee(int hoursWorked, int minutesWorked) { int quarterHours;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/02/2012 for the course COP 3014 taught by Professor Gaitros during the Fall '11 term at Florida State College.

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