当前位置:网站首页>C语言通过指针交换两个数
C语言通过指针交换两个数
2022-07-06 09:43:00 【芣苢的成长之路】
#include<stdio.h>
void swap1(int *p1,int *p2){
//p1,p2分别对应a,b的地址,*p1和*p2分别对应a和b的值
int p;//p是一个变量
p = *p1;
*p1 = *p2;
*p2 = p;
//通过地址进行值的交换操作,实际交换的是a,b的值
}
void swap2(int *p1,int *p2){
//p1,p2分别对应c,d的地址,*p1和*p2分别对应c和d的值
//这一步的操作是把p1 p2这两个地址当做形参进行操作
int *p;//p是一个指针
p = p1;
p1 = p2;
p2 = p;
//这个是形参交换,和原本的c d没有关系
}
int main() {
int a = 5,b = 10;
printf("原a b:%d %d\n",a,b);
swap1(&a,&b);
printf("swap1后a b:%d %d\n",a,b);
int c = 6,d = 8;
printf("原c d:%d %d\n",c,d);
swap2(&c,&b);
printf("swap2后c d:%d %d\n",c,d);
return 0;
}

边栏推荐
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
- Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
- 【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
- Essai de pénétration du Code à distance - essai du module b
- yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
- [elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
- Unity粒子特效系列-闪星星的宝箱
- [ASM] introduction and use of bytecode operation classwriter class
- Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
- The art of Engineering
猜你喜欢

网络分层概念及基本知识

分布式不来点网关都说不过去

Awk command exercise

Virtual machine startup prompt probing EDD (edd=off to disable) error

Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘

PyTorch 提取中间层特征?

BearPi-HM_ Nano development board "flower protector" case

Kali2021 installation and basic configuration
![[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias](/img/03/ece7f7b28cd9caea4240635548c77f.jpg)
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias

基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
随机推荐
Hongmeng introduction and development environment construction
10 advanced concepts that must be understood in learning SQL
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
Huawei certified cloud computing hica
Flink parsing (VII): time window
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
Openharmony developer documentation open source project
Guidelines for preparing for the 2022 soft exam information security engineer exam
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
PyTorch 提取中间层特征?
MySQL 8 sub database and table backup database shell script
BearPi-HM_ Nano development environment
Uipath browser performs actions in the new tab
BearPi-HM_ Nano development board "flower protector" case
Nodejs 开发者路线图 2022 零基础学习指南
adb常用命令
网络分层概念及基本知识
Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
Solrcloud related commands