Example call by reference & adress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <iostream> using namespace std; void Call_By_Reference (int& integer); void Call_By_Adress (int* integer); int& Return_Reference (int* integer); int* Return_Adress (int& integer); int main (int argc, char* argv[]) { int integer; printf ("%d\n", integer); integer = 0; Call_By_Reference (integer); printf ("%d\n", integer); integer = 0; Call_By_Adress (&integer); printf ("%d\n", integer); // == Gap == integer = 0; int Result_Reference = Return_Reference (&integer); printf ("%d\n", Result_Reference); integer = 0; int* Result_Adress = Return_Adress (integer); printf ("%d\n", *Result_Adress); return 0; } int* Return_Adress (int& integer) { return &(--(integer)); } int& Return_Reference (int* integer) { return --(*integer); } void Call_By_Adress (int* integer) { ++(*integer); return; } void Call_By_Reference (int& integer) { ++integer; return; } | cs |
0 개의 댓글:
댓글 쓰기