官术网_书友最值得收藏!

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 129字
  • 2021-07-02 23:07:26

What about functions with arguments?

Consider the following piece of code:

    fn main() 
    { 
        let a = 32; 
        let b = &a; 
    } 

We have created two variable bindings, with the second one (b) pointing at the address for a. The b variable doesn't contain the value of the a variable, but it points to the position a is held at, from which it can obtain a value (in other words, the value of b is borrowed from a).

In terms of our stack diagram, we have this:

The i binding points to address 0 and the b variable points to address 0, and this is the parameter being passed to second.

We can use this stack method to think about memory for a complex situation if you like.

主站蜘蛛池模板: 广昌县| 扶风县| 固始县| 登封市| 西和县| 青州市| 洪江市| 稷山县| 浠水县| 峨眉山市| 郎溪县| 双峰县| 雅江县| 岱山县| 龙山县| 宣威市| 青田县| 多伦县| 满洲里市| 东乌珠穆沁旗| 家居| 景洪市| 鹿邑县| 枞阳县| 玉环县| 班玛县| 海口市| 建德市| 石河子市| 博白县| 洞头县| 新民市| 雷州市| 松江区| 富民县| 互助| 晋江市| 大理市| 鄱阳县| 海兴县| 兴山县|