I wanted to prove that there is nothing known as (A protected memory address) and the whole story is just about the compiler, or the OS, or whatever application the hosted app is running on just make some checking on read and write requests the hosted app send to its superior process and this superior app or whatever you call it decide if this child process has the right to read or write to this specific memory location but this c++ code doesn't work in this essence so why :
#include <iostream>
int main()
{
const int x = 10;
std::cout << &x << std::endl; // So i can view address of x
std::cout << "x Before is equal "<< x <<std::endl;
int y ;
std:: cin >> std::hex >>y;
int *pinter = (int*)y ;
*pinter = 20;
std::cout << "x After is equal "<< x <<std::endl;
}
This code is supposed to get around the concept of c++ compiler setting x variable type to const int so that neither pointer to the variable (unlike in C in which pointers to constants can change the value of constant ) nor references to the variable can change the variable so this code is supposed to get address of variable x (of course after it's printed out) and then a pointer do the rest of the work , so what i messed here , cause it seams like this memory location is hardware protected( I know it's not but I am very confused)