Run the code below:
#include <iostream>
int main()
{
const int NUM = 1;
int *p = (int *)&NUM;
*p = 2;
std::cout << *p << "\n";
std::cout << NUM << "\n";
return 0;
}
The output of the program above is: 2 1
The expected output was: 2 2
Can anyone please explain why the value of NUM is 1? The same can be tested with https://www.onlinegdb.com/