c模擬c++ const 轉換

#include <stdio.h>ios

int main(){c++

const int constant = 21;
const int* const_p = &constant;
int* modifier = (int*)(const_p);spa

*modifier=10;
printf("%d \n",constant);
return 0;
}io

結果是10stream

#include <iostream>
using namespace std;
int main(){di

const int constant = 21;
const int* const_p = &constant;
int* modifier = (int*)(const_p);ant

*modifier=10;
cout<<constant<<endl;
return 0;
}co

結果是21,這種模擬,對c++屬於未定義操做~return

相關文章
相關標籤/搜索