Three, use pointers and functions to exchange the values of two numbers

Use pointers and functions to exchange the values ​​of two numbers

-------------------------------------------------- ---------------------------------------
C language source code

#include<stdio.h>

//利用指针和函数交换两数的值
void Exchange(int* p,int* q)//交换函数
{
    
    
	int tmp;
	tmp = *p;
	*p = *q;
	*q = tmp;
}

int main()
{
    
    
	int a = 10;
	int b = 20;
	printf("交换前a=%d,b=%d\n",a,b);
	Exchange(&a,&b);//调用函数时,分别将a和b的地址作为实参传入交换函数
	printf("交换后a=%d,b=%d",a,b);
	return 0;
}

-------------------------------------------------- ---------------------------------------
Execution result
Insert picture description here
Day3-------- -------------------------------------------------- -----------------------

Buying porridge in the cafeteria, a girl next to me said that she wanted millet porridge, but the aunt gave two copies of the money. The girl swiped the card and asked: Has the price of porridge increased? The aunt looked at me and the girl and asked: Are you not a couple? The girl turned her head and looked at me with a smile and said: No. It feels good to have a girlfriend T^TInsert picture description here

Guess you like

Origin blog.csdn.net/xiaoxiaoguailou/article/details/111144065