As far as I know, you can change the value of a const if you dereference a pointer to it (int *prt). However, I'd expect this to return x = 20, not x = 10.
#include <stdio.h>
int main() {
const int x = 10;
int* y = &x;
*y = 20;
printf("x = %i\n", x);
return 0;
}
The compilers (both gcc and clang) throw a warning, but let me compile (as expected). I did my research before posting, but everything suggests I should be able to change x. The code looks almost exactly like this which I tried too, and I couldn't manage to change var's value.
Also read this, this and this which further prove I should be getting the expected output x = 20 and not x = 10.
Running macOS on a 2020 M1 MacBook Air.