+ 1
Is there any way to change the value of constant variables during program execution in C?
I LOVE C PROGRAMMING 😘
6 ответов
+ 4
Yes, but it is not enough to use a pointer as it has an undefined behaviour (meaning that different compilers may give you different results). You have to instead cast the pointer to int* and dereference it again. I'll explain better with code:
const int c = 10;
*(int *)&c = 0;
printf("c is %d", c); //c is 0
+ 2
hey dear i know all this stuff i just post a question because I didn't before 😂
and ya the value of const var can be change by using pointer which pointing to that var but the pointer must not be a const .
+ 2
Jan Markus thank god, that u understand me in such a short sentences
+ 2
Stefano Prosperi 👏👍, but he is asking if there is a Way,,,
+ 2
thanks stefano for such a great info really clear out all my doubt.
+ 1
yes, technically u can use pointer; make it point to the value and replace it👍
guest u need much more lesson on using them😨😨😨😨
hmm, just kidding..