Value delivery mechanism

① If the parameter is the basic data type, the argument is assigned to parameter data stored in the real argument values

② If the data type parameter is a reference, assigned to parameter argument at this time is stored in the data address argument values.

As to why this is the above, I suggest you go look at the different types of data in the stack and heap memory space to open up, you will understand this mechanism.

The method of switching the two numbers is:

void swap(int *a, int *b){
		int temp = *a;
		*a = *b;
		*b = temp;
}
int main(){
		int a = 1, b = 2;
		swap(&a, &b);
		printf(“%d  %d”, a, b);
		return 0;
}
Published 48 original articles · won praise 5 · Views 785

Guess you like

Origin blog.csdn.net/weixin_43899266/article/details/103497976