4-Pass By Reference

4-Pass By Reference - / / / / / / / Pass by reference...

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

View Full Document Right Arrow Icon
// Pass by reference // Previously we have used pointers to get the memory // address of the variable that is being passed in. // Having the memory address to the actual variable // instead of a copy of that variable allowed us // to make changes to that variable and have those // changes persist past the function call #include <iostream> using std::cout; // allows us to only mention cout without having to qualify it using std::cin; // same thing here, the scope operator :: using std::endl; // makes this work, more on this later float passByValue(float data) { // mutate data cout << "\nIncoming data: " << data << "\n"; data *= 2; cout << "Mutated data: " << data << endl; return data; } { // mutate data again cout << "\nIncoming data: " << data << "\n"; data *= 2; cout << "Mutated data: " << data << endl; } int main (void) { float someValue = 14.3f; float someData = 34.1f; float afterWords = 0.0f; cout << "Original Data:\n"; cout << "someValue: " << someValue
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

4-Pass By Reference - / / / / / / / Pass by reference...

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

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