Swift-類與結構體自測題

來源:互聯網
上載者:User
<pre name="code" class="python">1.有一個結構體和類,定義如下<pre name="code" class="java">struct Resolution {    var width = 0    var heigth = 0}class VideoMode {    var resolution = Resolution()    var interlaced = false    var frameRate = 0.0    var name: String?}


 


let hd = Resolution(width: 1920, height: 1080)var cinema = hdcinema.width = 2048println("cinema is now  \(cinema.width) pixels wide")<pre name="code" class="python">println("hd is now  \(hd.width) pixels wide")

 上面當輸出語句分別輸出什麼。 

let tenEighty = VideoMode()tenEighty.resolution = hdtenEighty.interlaced = truetenEighty.name = "1080i"tenEighty.frameRate = 25.0let alsoTenEighty = tenEightyalsoTenEighty.frameRate = 30.0println("The frameRate property of tenEighty is now \(tenEighty.frameRate)")

上面當輸出呢。


這就是實值型別和參考型別的區別。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.