The book said I cannot change the value of const once I gave it a number, but it seems I can still give it a number even if it was given.
#include<iostream>
using namespace std;
const int fansc(100);
cout<< fansc << endl; //output:100
int fansc(20);
cout<< fansc << endl;//output:20
The C++ code you gave won't compile, and rightly so. A
constvariable(a) is, well, ... constant. The error is shown in the following program and transcript:That leaves the Anaconda bit that you mention in a comment. I have little experience with that but it seems to me the only way that would work is if the second
fanscdefinition was somehow created in a different scope to the first. In real C++ code, that would go something like:And the output of that is:
(a) Yes, I know that's a self-contradiction :-)