当前位置:网站首页>C language exchanges two numbers through pointers
C language exchanges two numbers through pointers
2022-07-06 18:06:00 【The way of growth of Peng】
#include<stdio.h>
void swap1(int *p1,int *p2){
//p1,p2 They correspond to each other a,b The address of ,*p1 and *p2 They correspond to each other a and b Value
int p;//p It's a variable
p = *p1;
*p1 = *p2;
*p2 = p;
// Exchange values through addresses , The actual exchange is a,b Value
}
void swap2(int *p1,int *p2){
//p1,p2 They correspond to each other c,d The address of ,*p1 and *p2 They correspond to each other c and d Value
// The operation of this step is to put p1 p2 These two addresses operate as formal parameters
int *p;//p It's a pointer
p = p1;
p1 = p2;
p2 = p;
// This is the formal parameter exchange , And the original c d It doesn't matter.
}
int main() {
int a = 5,b = 10;
printf(" primary a b:%d %d\n",a,b);
swap1(&a,&b);
printf("swap1 after a b:%d %d\n",a,b);
int c = 6,d = 8;
printf(" primary c d:%d %d\n",c,d);
swap2(&c,&b);
printf("swap2 after c d:%d %d\n",c,d);
return 0;
}

边栏推荐
- SAP UI5 框架的 manifest.json
- How to solve the error "press any to exit" when deploying multiple easycvr on one server?
- sql语句优化,order by desc速度优化
- STM32按键状态机2——状态简化与增加长按功能
- 2019阿里集群数据集使用总结
- Jerry's watch reading setting status [chapter]
- [introduction to MySQL] the first sentence · first time in the "database" Mainland
- 编译原理——预测表C语言实现
- After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
猜你喜欢

How to use scroll bars to dynamically adjust parameters in opencv

The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement

78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO

酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
![[introduction to MySQL] the first sentence · first time in the](/img/1e/2401d821b1008922bc5f8a15de31f9.png)
[introduction to MySQL] the first sentence · first time in the "database" Mainland

Windows连接Linux上安装的Redis

J'aimerais dire quelques mots de plus sur ce problème de communication...

Is it meaningful for 8-bit MCU to run RTOS?

Optimization of middle alignment of loading style of device player in easycvr electronic map

基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
随机推荐
declval(指导函数返回值范例)
Introduction to the usage of model view delegate principal-agent mechanism in QT
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Why should Li Shufu personally take charge of building mobile phones?
面试突击62:group by 有哪些注意事项?
MSF横向之MSF端口转发+路由表+SOCKS5+proxychains
递归的方式
Unity particle special effects series - treasure chest of shining stars
J'aimerais dire quelques mots de plus sur ce problème de communication...
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
Pytest learning ----- pytest operation mode and pre post packaging of interface automation testing
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
2019 Alibaba cluster dataset Usage Summary
std::true_ Type and std:: false_ type
Getting started with pytest ----- allow generate report
Smart street lamp based on stm32+ Huawei cloud IOT design
Distinguish between basic disk and dynamic disk RAID disk redundant array
编译原理——预测表C语言实现
scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
Pytest learning ----- pytest confitest of interface automation test Py file details