无标题文章

2016-11-18  本文已影响2人  祺了个祺

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.画驯鹿流程图

上一篇下一篇

猜你喜欢

热点阅读