久久久久久久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 仍然相關嗎?)
主站蜘蛛池模板: 国产九九精品 | 一级黄色免费 | 99看片| 国产色自拍 | av免费看片 | 69免费视频 | 久草新视频 | 免费看黄色录像 | 91伊人网| 亚洲精品影院 | 一区二区三区免费 | 在线观看中文字幕 | 99久久婷婷国产综合精品草原 | 国产a√ | 六月丁香激情 | 欧美一级网站 | 日本乱轮视频 | 97中文字幕 | 在线视频日韩 | 久久精品国产精品 | 久久久久久久 | 精品在线免费视频 | 一区二区不卡 | 伊人av网 | 天天操综合网 | 国产原创精品 | 午夜美女福利 | 韩国精品一区 | 狠狠涩 | 精品久久久久久一区二区里番 | 一级免费视频 | 天堂成人av | 免费看黄色小视频 | 一区二区欧美日韩 | 欧美在线一区二区三区 | 色吧综合 | 黄色福利 | 一级片免费观看 | 四虎影院在线免费观看 | 亚洲免费一区二区 | www.久久久 |