Beginning Programming with C++ For Dummies by Stephen R. Davis

Beginning Programming with C++ For Dummies by Stephen R. Davis

Author:Stephen R. Davis
Language: eng
Format: epub, pdf
ISBN: 9781118823934
Publisher: Wiley
Published: 2014-10-06T10:31:28+00:00


// wait until user is ready before terminating program

// to allow the user to see the program results

cout << "Press Enter to continue..." << endl;

cin.ignore(10, '\n');

cin.get();

return 0;

}

The following is the output from this program:

The value of nArg1 is 1

The value of nArg2 is 2

Calling fn(int, int)

Returned from fn(int, int)

The value of nArg1 is 1

The value of nArg2 is 2

Calling fn(int*, int*)

Returned from fn(int*, int*)

The value of nArg1 is 10

The value of nArg2 is 20

Press Enter to continue …

This program declares the variables nValue1 and nValue2 and initializes them to 1 and 2, respectively. The program then displays their value just to make sure. Next, the program calls the fn(int, int), passing the value of the two variables. That function modifies the value of its arguments, but this has no effect on nValue1 and nValue2 as demonstrated by the fact that their value is unchanged after control returns to main().

The second call passes not the values of nValue1 and nValue2 but their addresses to the function fn(int*, int*). This time, the changes to pnArg1 and pnArg2 are retained even after control returns to main().

Notice that there is no confusion between the overloaded functions fn(int, int) and fn(int*, int*). The types of the arguments are easily distinguished.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.