Just remember one sentence:
General references by value is to generate a temporary object, and call by reference is to call the parameter itself.
Reference to the following C language code appreciated:
Implement two methods in test.h file
#include <stdio.h>
/ * Swapping two numbers * / void Exchange ( int X, int Y) { int TEMP; TEMP = X; X = Y; Y = TEMP; the printf ( " the first number after the exchange: \ n% d \ n exchange after the second number: \ n-% D \ n- " , X, Y); } / * exchange pointers two numbers * / void exchangeAddress ( int * X, int * Y) { int TEMP * = X; * X * = Y; * Y = TEMP; the printf ( "The first number after the exchange: \ n% d \ n After exchanging a second number: \ n% d \ n " , X *, * Y); }
Call these two methods as follows test.c file:
#include <stdio.h> #include "test.h" int main(){ int a, b; printf("请输入a: \n"); scanf("%d",&a); printf("请输入b: \n"); scanf("%d",&b); exchange(a,b); printf("交换后:\n a=%d\n b=%d\n",a,b) ; exchangeAddress(&a,&b); printf(""Address exchange: \% Na = D \ D% Nb = \ n-,a,b) ; }
Print Results:
Reproduced in: https: //www.cnblogs.com/lovemargin/p/10562386.html