Sololearn: Learn to Code
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?'
1st Jun 2020, 2:48 PM
HonFu
HonFu - avatar
+ 4
No. You can't modify the value of const. If you will try it will give an error.
1st Jun 2020, 10:33 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 2
Try this in code playground #include <stdio.h> int main() { const a=10; a++; return 0; } u will find the error
1st Jun 2020, 10:40 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 1
By writing const you save yourself from accidentally changing the value deeper down in your program.
1st Jun 2020, 10:39 AM
HonFu
HonFu - avatar
+ 1
By using a pointer we can.
1st Jun 2020, 11:17 AM
Sadir Irfan
Sadir Irfan - avatar
+ 1
But why is this so, a type qualifier means i should be universal. We cannot able to change that cont value. But here..
1st Jun 2020, 2:41 PM
Sadir Irfan
Sadir Irfan - avatar
0
But i can change the value.
1st Jun 2020, 10:36 AM
Sadir Irfan
Sadir Irfan - avatar