久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='2wGAP'></tfoot>

    <i id='2wGAP'><tr id='2wGAP'><dt id='2wGAP'><q id='2wGAP'><span id='2wGAP'><b id='2wGAP'><form id='2wGAP'><ins id='2wGAP'></ins><ul id='2wGAP'></ul><sub id='2wGAP'></sub></form><legend id='2wGAP'></legend><bdo id='2wGAP'><pre id='2wGAP'><center id='2wGAP'></center></pre></bdo></b><th id='2wGAP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2wGAP'><tfoot id='2wGAP'></tfoot><dl id='2wGAP'><fieldset id='2wGAP'></fieldset></dl></div>

    <small id='2wGAP'></small><noframes id='2wGAP'>

      <legend id='2wGAP'><style id='2wGAP'><dir id='2wGAP'><q id='2wGAP'></q></dir></style></legend>
        <bdo id='2wGAP'></bdo><ul id='2wGAP'></ul>

        c和c++上下文中靜態、自動、全局和局部變量的區

        Difference between static, auto, global and local variable in the context of c and c++(c和c++上下文中靜態、自動、全局和局部變量的區別)
      1. <i id='To47a'><tr id='To47a'><dt id='To47a'><q id='To47a'><span id='To47a'><b id='To47a'><form id='To47a'><ins id='To47a'></ins><ul id='To47a'></ul><sub id='To47a'></sub></form><legend id='To47a'></legend><bdo id='To47a'><pre id='To47a'><center id='To47a'></center></pre></bdo></b><th id='To47a'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='To47a'><tfoot id='To47a'></tfoot><dl id='To47a'><fieldset id='To47a'></fieldset></dl></div>

        <small id='To47a'></small><noframes id='To47a'>

          <tbody id='To47a'></tbody>

          <tfoot id='To47a'></tfoot>
          <legend id='To47a'><style id='To47a'><dir id='To47a'><q id='To47a'></q></dir></style></legend>
          • <bdo id='To47a'></bdo><ul id='To47a'></ul>

                • 本文介紹了c和c++上下文中靜態、自動、全局和局部變量的區別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我對 staticautogloballocal 變量有點困惑.

                  I’ve a bit confusion about static, auto, global and local variables.

                  我在某處讀到 static 變量只能在函數內訪問,但在函數返回后它們仍然存在(保留在內存中).

                  Somewhere I read that a static variable can only be accessed within the function, but they still exist (remain in the memory) after the function returns.

                  不過,我也知道local變量也有同樣的作用,那么有什么區別呢?

                  However, I also know that a local variable also does the same, so what is the difference?

                  推薦答案

                  這里有兩個獨立的概念:

                  There are two separate concepts here:

                  • 范圍,它決定了可以訪問名稱的位置,以及
                  • 存儲持續時間,決定了何時創建和銷毀變量.
                  • scope, which determines where a name can be accessed, and
                  • storage duration, which determines when a variable is created and destroyed.

                  局部變量(迂腐地,具有塊作用域的變量)只能在聲明它們的代碼塊內訪問:

                  Local variables (pedantically, variables with block scope) are only accessible within the block of code in which they are declared:

                  void f() {
                      int i;
                      i = 1; // OK: in scope
                  }
                  void g() {
                      i = 2; // Error: not in scope
                  }
                  

                  全局變量(迂腐地,具有文件范圍(在C中)或命名空間范圍(在C++中)的變量)可以在任何時候訪問在他們聲明之后:

                  Global variables (pedantically, variables with file scope (in C) or namespace scope (in C++)) are accessible at any point after their declaration:

                  int i;
                  void f() {
                      i = 1; // OK: in scope
                  }
                  void g() {
                      i = 2; // OK: still in scope
                  }
                  

                  (在 C++ 中,情況更加復雜,因為命名空間可以關閉和重新打開,并且可以訪問當前范圍以外的范圍,并且名稱也可以具有類范圍.但這變得非常偏離主題.)

                  (In C++, the situation is more complicated since namespaces can be closed and reopened, and scopes other than the current one can be accessed, and names can also have class scope. But that's getting very off-topic.)

                  自動變量(迂腐,具有自動存儲持續時間的變量)是局部變量,其生命周期在執行離開其作用域時結束,并在重新進入作用域時重新創建.

                  Automatic variables (pedantically, variables with automatic storage duration) are local variables whose lifetime ends when execution leaves their scope, and are recreated when the scope is reentered.

                  for (int i = 0; i < 5; ++i) {
                      int n = 0;
                      printf("%d ", ++n);  // prints 1 1 1 1 1  - the previous value is lost
                  }
                  

                  靜態變量(迂腐地,具有靜態存儲期的變量)的生命周期一直持續到程序結束.如果它們是局部變量,那么當執行離開它們的作用域時它們的值仍然存在.

                  Static variables (pedantically, variables with static storage duration) have a lifetime that lasts until the end of the program. If they are local variables, then their value persists when execution leaves their scope.

                  for (int i = 0; i < 5; ++i) {
                      static int n = 0;
                      printf("%d ", ++n);  // prints 1 2 3 4 5  - the value persists
                  }
                  

                  請注意,static 關鍵字除了靜態存儲持續時間之外還有多種含義.在全局變量或函數上,它賦予它內部鏈接,以便其他翻譯單元無法訪問它;在 C++ 類成員上,這意味著每個類有一個實例,而不是每個對象一個.此外,在 C++ 中,auto 關鍵字不再表示自動存儲持續時間;它現在意味著從變量的初始值設定項推導出的自動類型.

                  Note that the static keyword has various meanings apart from static storage duration. On a global variable or function, it gives it internal linkage so that it's not accessible from other translation units; on a C++ class member, it means there's one instance per class rather than one per object. Also, in C++ the auto keyword no longer means automatic storage duration; it now means automatic type, deduced from the variable's initialiser.

                  這篇關于c和c++上下文中靜態、自動、全局和局部變量的區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Why do two functions have the same address?(為什么兩個函數的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                  mixing templates with polymorphism(混合模板與多態性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)
                  1. <tfoot id='Q3aPq'></tfoot>

                    <legend id='Q3aPq'><style id='Q3aPq'><dir id='Q3aPq'><q id='Q3aPq'></q></dir></style></legend>
                      <i id='Q3aPq'><tr id='Q3aPq'><dt id='Q3aPq'><q id='Q3aPq'><span id='Q3aPq'><b id='Q3aPq'><form id='Q3aPq'><ins id='Q3aPq'></ins><ul id='Q3aPq'></ul><sub id='Q3aPq'></sub></form><legend id='Q3aPq'></legend><bdo id='Q3aPq'><pre id='Q3aPq'><center id='Q3aPq'></center></pre></bdo></b><th id='Q3aPq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Q3aPq'><tfoot id='Q3aPq'></tfoot><dl id='Q3aPq'><fieldset id='Q3aPq'></fieldset></dl></div>
                    • <small id='Q3aPq'></small><noframes id='Q3aPq'>

                      • <bdo id='Q3aPq'></bdo><ul id='Q3aPq'></ul>

                              <tbody id='Q3aPq'></tbody>
                            主站蜘蛛池模板: 精品区一区二区 | 一区二区三区在线观看视频 | 久久国产一区二区 | 一级a性色生活片久久毛片 一级特黄a大片 | 在线观看中文字幕视频 | 日韩久久精品视频 | 日韩亚洲视频 | 麻豆久久久久久 | 国产黄色大片在线观看 | 午夜成人免费视频 | 日韩一区二区三区在线视频 | 一级在线观看 | 亚洲狠狠爱一区二区三区 | 日韩免费在线 | 精品国产一区二区三区性色av | 成人夜晚看av | 日韩精品1区2区3区 成人黄页在线观看 | 97国产精品 | 91爱爱·com | 欧美日韩精品免费 | 神马久久久久久久久久 | 一级a性色生活片久久毛片 午夜精品在线观看 | 国产精品资源在线观看 | 亚洲欧洲一区二区 | 欧美在线观看一区 | 久久久久久久久久久久一区二区 | 夜夜操天天干 | 99资源站| 国产精品久久国产精品久久 | 国产成人高清在线观看 | 亚洲狠狠丁香婷婷综合久久久 | 国色天香成人网 | 鸡毛片| 国产精品美女久久久久久久网站 | 日本网站免费在线观看 | 成年无码av片在线 | 欧美一区二区成人 | 91国产视频在线观看 | 孕妇一级毛片 | 日本中文字幕一区 | 亚洲成人精品国产 |