#include // The C Programing Language // Chapter 7 Functions //7.2 Parameter Transfer INT E (Const Int Ref) {std :: cout << "/ n ref" << ref; return 2 * ref; } Int F (const INT & REF) {std :: cout << "/ n ref" << ref; return 2 * ref;} // incoming a reference, but cannot do any modifications to this reference // e The same function is implemented with f, but E can be introduced into constant parameters INT G (int Arg) {std :: cout << "/ ng (arg) 1 =" << arg; arg * = 2; std :: cout << "/ ng (arg) 2 =" << arg; return arg;} // Incoming an int value, can be modified to this value in G (), but does not affect G () INT H ( INT & Arg) {std :: cout << "/ NH (arg) 1 =" << arg; arg * = 2; std :: cout << "/ NH (arg) 2 =" << arg; return } // Incomparted INT ARG reference INT i (int * p) {std :: cout << "/ ni () 1 = << * p; * p * = 2; std :: cout <<" / Ni () 2 = "<< * p; return * p;} // Incomputeng, consistent with the function h function int Main () {
INT b = 2; g (b); std :: cout << "/ nb =" << b; h (b); std :: cout << "/ nb =" << b; std :: cout < <"/ n --------------"; E (2); f (2); g (2); // h (2); // error, there must be one It is indeed a variable that can be referenced instead of a temporary amount std :: cout << "/ n --------------"; float c = 1.0f; g ((int) c) ; // h (int (c)); // error, int (c) produced a temporary amount std :: cout << "/ N --------------" < <& B; I (& B); std :: cout << "/ nb =" << b; getchar ();
The result of the operation is as follows