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

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

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

      <legend id='rgXkY'><style id='rgXkY'><dir id='rgXkY'><q id='rgXkY'></q></dir></style></legend>
    1. <tfoot id='rgXkY'></tfoot>
          <bdo id='rgXkY'></bdo><ul id='rgXkY'></ul>

        為什么在打印未初始化的變量時會看到奇怪的值

        Why do I see strange values when I print uninitialized variables?(為什么在打印未初始化的變量時會看到奇怪的值?)
        • <tfoot id='Ggutq'></tfoot>
        • <small id='Ggutq'></small><noframes id='Ggutq'>

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

                <tbody id='Ggutq'></tbody>

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

                  本文介紹了為什么在打印未初始化的變量時會看到奇怪的值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  在下面的代碼中,變量沒有初始值并打印了這個變量.

                  In the following code, the variable has no initial value and printed this variable.

                  int var;
                  cout << var << endl;
                  

                  輸出:2514932

                  double var;
                  cout << var << endl;
                  

                  輸出:1.23769e-307

                  output : 1.23769e-307

                  我不明白這些輸出數字.誰能給我解釋一下?

                  I don't understand these output numbers. Can any one explain this to me?

                  推薦答案

                  簡單地說,var 沒有被初始化,讀取一個未初始化的變量會導致 未定義的行為.

                  Put simply, var is not initialized and reading an uninitialized variable leads to undefined behavior.

                  所以不要這樣做.一旦你這樣做,你的程序就不再保證按你說的做.

                  So don't do it. The moment you do, your program is no longer guaranteed to do anything you say.

                  正式地,讀取"一個值意味著對其執行左值到右值的轉換.§4.1 指出...如果對象未初始化,則需要進行此轉換的程序具有未定義的行為."

                  Formally, "reading" a value means performing an lvalue-to-rvalue conversion on it. And §4.1 states "...if the object is uninitialized, a program that necessitates this conversion has undefined behavior."

                  實際上,這只是意味著該值是垃圾(畢竟,很容易看到讀取 int,例如,只是獲取隨機位),但我們不能得出結論 這個,否則你會定義未定義的行為.

                  Pragmatically, that just means the value is garbage (after all, it's easy to see reading an int, for example, just gets random bits), but we can't conclude this, or you'd be defining undefined behavior.

                  舉一個真實的例子,考慮:

                  For a real example, consider:

                  #include <iostream>
                  
                  const char* test()
                  {
                      bool b; // uninitialized
                  
                      switch (b) // undefined behavior!
                      {
                      case false:
                          return "false";      // garbage was zero (zero is false)
                      case true: 
                          return "true";       // garbage was non-zero (non-zero is true)
                      default:
                          return "impossible"; // options are exhausted, this must be impossible...
                      }
                  }
                  
                  int main()
                  {
                      std::cout << test() << std::endl;
                  }
                  

                  天真地,人們會得出結論(通過評論中的推理)這永遠不應該打印 "impossible";但是對于未定義的行為,一切皆有可能.用 g++ -02 編譯它.

                  Na?vely, one would conclude (via the reasoning in the comments) that this should never print "impossible"; but with undefined behavior, anything is possible. Compile it with g++ -02.

                  這篇關于為什么在打印未初始化的變量時會看到奇怪的值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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. <small id='c7ZwF'></small><noframes id='c7ZwF'>

                      <bdo id='c7ZwF'></bdo><ul id='c7ZwF'></ul>
                    • <tfoot id='c7ZwF'></tfoot>

                        <legend id='c7ZwF'><style id='c7ZwF'><dir id='c7ZwF'><q id='c7ZwF'></q></dir></style></legend>
                          <tbody id='c7ZwF'></tbody>
                            <i id='c7ZwF'><tr id='c7ZwF'><dt id='c7ZwF'><q id='c7ZwF'><span id='c7ZwF'><b id='c7ZwF'><form id='c7ZwF'><ins id='c7ZwF'></ins><ul id='c7ZwF'></ul><sub id='c7ZwF'></sub></form><legend id='c7ZwF'></legend><bdo id='c7ZwF'><pre id='c7ZwF'><center id='c7ZwF'></center></pre></bdo></b><th id='c7ZwF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='c7ZwF'><tfoot id='c7ZwF'></tfoot><dl id='c7ZwF'><fieldset id='c7ZwF'></fieldset></dl></div>
                            主站蜘蛛池模板: 久综合 | 精品一区在线免费观看 | 亚洲天堂中文字幕 | 午夜欧美一区二区三区在线播放 | 国产在视频一区二区三区吞精 | 天堂亚洲 | 青青草国产在线观看 | 成人欧美一区二区三区视频xxx | 国产精品美女久久久久久免费 | 天天操网 | 久久精品一区二区三区四区 | 亚洲精选一区 | 中文字幕1区2区3区 亚洲国产成人精品女人久久久 | 欧美日韩精品一区 | 每日更新av | 久草新在线 | 99久久久久国产精品免费 | 国产日韩欧美 | 久久一级大片 | 免费在线看黄视频 | 欧美一区二区三区在线观看视频 | 二区中文字幕 | 一区免费观看 | 亚洲免费一 | av一级久久| 中文字幕亚洲国产 | 99一区二区 | 国产成人综合一区二区三区 | 中文字幕日韩欧美一区二区三区 | 中文字幕在线精品 | 日韩av三区| 亚洲在线一区二区 | 免费看黄视频网站 | 久久免费香蕉视频 | 毛片韩国 | 观看av| 日韩久久精品电影 | 青青草av网站 | 欧美男人天堂 | 欧美亚洲另类在线 | 逼逼网 |