+ 2
How to change value of constant in C
4 Antworten
+ 2
Attempting to modify a constant variable is undefined behavior. It could be placed in read only memory or optimized away by the compiler since it's value is constant, so you shouldn't try to do it.
+ 1
const int x = 5;
int* p = (int*)&x;
*p = 22;
Still undefined behavior but that's how it can be done
+ 1
Neither method in this stack overflow answer appears to work here; half the other stuff I tried aborts the runtime somehow (causing no output).
https://stackoverflow.com/a/583104
Emphasis on 'undefined behavior' as noted in @aklex's answers.
0
I have read in many clauses of C books that you can change change constant value in c using pointers but how it wasn't given