无标题文章

swift 语法

1.inout()

希望传入参数通过函数改变

func swapTwoInts( a:Int, b:Int){

var a = a

var b = b

let t = a

a = b

b = t

}

var x = 0,y = 100

print("x = \(x) ;y = \(y)")

swapTwoInts(a: x, b: y)

print("x = \(x) ;y = \(y)")    //(x=0,y=100)



func swapTwoInts2( a:inout Int, b:inout Int){

let t = a

a = b

b = t

}

var f = 0,g = 100

print("f = \(f) ;g = \(g)")

swapTwoInts2(a: &f, b: &g)

print("f = \(f) ;g = \(g)")   //(f=100,g=0)

2.画驯鹿流程图

你可能感兴趣的:(无标题文章)