New course! Every coder should learn Generative AI!
Try a free lesson+ 1
sadir irfan, initially you asked, if it's possible to change a const value.
Then, a bit later, you say that you can do it, and how - by pointer.
Please use this Q&A forum only for questions YOU need an answer for!
Otherwise, your question should have just started with what you know, followed by your actual question, so that users can help you directly and not tell you something you already know.
For example:
'Const is supposed to prevent that a value is changed.
However, by using a pointer, I can change the value anyway.
What is the reason for this?'
+ 4
No.
You can't modify the value of const.
If you will try it will give an error.
+ 2
Try this in code playground
#include <stdio.h>
int main() {
const a=10;
a++;
return 0;
}
u will find the error
+ 1
By writing const you save yourself from accidentally changing the value deeper down in your program.
+ 1
By using a pointer we can.
+ 1
But why is this so, a type qualifier means i should be universal. We cannot able to change that cont value. But here..
0
But i can change the value.