All pastes #1195508 Raw Edit

Unnamed

public cpp v1 · immutable
#1195508 ·published 2008-09-06 03:51 UTC
rendered paste body
//2.3.1 Source code//prob3.cpp#include <iostream>using namespace std;//---------------------------------------------------------------------------void f1(int x) {                //pass by valuex -= 10;cout << "In: " << x << endl;}void f2(int &x) {               //pass by referencex -= 10;cout << "In: " << x << endl;}void f3(int const &x) {         // pass by const referenceint z = x - 10;cout << "In: " << x << endl << "or " << z << " after mod" << endl;}void f4(int *x) {               // pass by const reference*x -= 10;cout << "In: " << *x << endl;}//---------------------------------------------------------------------------void main() {int x = 100;cout << "Pass to a function by value"<<endl;cout << "Before: " << x <<endl;f1(x);cout << "After: " << x <<endl;cout << "Pass to a function by reference"<<endl;cout << "Before: " << x <<endl;int &refX = x;f2(refX);cout << "After: " << x <<endl;cout << "Pass to a function by const reference"<<endl;cout << "Before: " << x <<endl;f3(x);cout << "After: " << x <<endl;cout << "Pass to a function by pointer/address"<<endl;cout << "Before: " << x <<endl;int *pX = &x;f4(pX);cout << "After: " << x <<endl;system("pause");}//---------------------------------------------------------------------------