久久久久久久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精品国产乱码久久久久久久久 | 综合二区 | av色噜噜| 超黄毛片| 欧美日韩在线高清 | 九九爱这里只有精品 | 国产一级一片免费播放 | 成人免费高清 | 天堂av在线影院 | 国产欧美一区二区三区国产幕精品 | 狠狠插狠狠操 | www狠狠干 | 99精品免费视频 | 99国产精品一区二区三区 | 国产精品久久久久久久久久免费 | 久久三区| 男人的天堂avav | 亚洲国产网 | av在线视 | 在线a视频网站 | 一区二区三区欧美在线观看 | 欧美在线一区二区视频 | 亚洲黄色成人网 | 91亚洲欧美| 久久日韩粉嫩一区二区三区 | 国产精品不卡一区二区三区 | 欧美精品一区二区三区在线 | 国产1区2区在线观看 | 欧美日日 | 久久免费精品视频 | 黄色成人在线观看 | 99热国产在线播放 | 欧美久久国产 | 精品综合 | 亚洲国产一区在线 | 亚洲欧美国产精品久久 | 亚洲第一色av | 91久久夜色精品国产网站 | 日日操夜夜干 | 在线视频 欧美日韩 | 91久久精品国产91久久 |