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

同一內存地址的兩個不同值

Two different values at the same memory address(同一內存地址的兩個不同值)
本文介紹了同一內存地址的兩個不同值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

代碼

#include 使用命名空間標準;int main() {const int N = 22;int * pN = const_cast(&N);*pN = 33;cout<<N<<'	' <<&N <<結束;cout<<*pN<<'	' <<pN<<結束;}

輸出

<塊引用>

22 0x22ff74

33 0x22ff74

為什么同一個地址有兩個不同的值?

解決方案

為什么同一個地址有兩個不同的數據?

沒有.編譯器可以優化任何對 const 的提及,就好像您在其中寫入了它的編譯時值一樣.

請注意,如果您做了一些討厭的技巧,例如寫入為常量保留的內存,編譯器也可以生成在您運行時擦除硬盤的代碼.

Code

#include <iostream>
using namespace std;

int main() {
    const int N = 22;
    int * pN = const_cast<int*>(&N);
    *pN = 33;
    cout << N << '	' << &N << endl;
    cout << *pN << '	' << pN << endl;
}

Output

22 0x22ff74

33 0x22ff74

Why are there two different values at the same address?

解決方案

Why are there two different datas at the same address?

There aren't. The compiler is allowed to optimize any mention of a const to be as though you had written its compile-time value in there.

Note that the compiler is also allowed to generate code that erases your hard disk when you run it if you do nasty tricks like writing to memory reserved for consts.

這篇關于同一內存地址的兩個不同值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉換為 HSV 并將 HSV 轉換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉換為字符串?)
When to use inline function and when not to use it?(什么時候使用內聯函數,什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);)
Is TCHAR still relevant?(TCHAR 仍然相關嗎?)
主站蜘蛛池模板: 日韩精品成人免费观看视频 | 日本欧美在线观看 | 欧美日在线 | 中文在线观看免费网站 | 国产精品久久久久久无人区 | 精品久久国产 | 91精品久久久久久久久久 | 美女在线播放 | 长河落日电视连续剧免费观看 | 99精品网站| 成人免费毛片男人用品 | 国产成人91 | 免费看的黄网站 | 福利视频网址 | 男女瑟瑟视频 | 亚洲精品黄色 | 99一区二区 | 欧美韩日| 9999精品视频 | 国产91精品看黄网站在线观看 | 97精品在线视频 | 在线观看黄色网 | 97国产在线视频 | 免费淫片| 国产1级片 | 五月天婷婷激情 | 欧美日韩久久久 | 免费黄网站在线观看 | 亚洲人在线观看 | a级毛毛片 | 日韩欧美黄色片 | 九九热在线精品 | 午夜在线观看视频网站 | 国产欧美精品一区二区 | 依人在线 | 亚洲一级特黄 | 黄在线观看 | 成人在线免费网站 | 国内精品视频 | 欧美视频一二三区 | 91国内精品 |