Swift中 能交换两个变量的数值

来源:互联网 发布:淘宝客服兼职工作 编辑:程序博客网 时间:2024/05/16 19:27

这里写图片描述

/* 编写一个程序,能交换两个变量的数值 例如: 变量a值为20,变量b值为30,调用函数后,a的值变为30,b 的值变为20*/func swap(a: inout Int , b:inout Int){    let temp = a    a = b    b = temp}var x = 20 , y = 30swap(a:&x , b:&y)print(x,y)