This question already has an answer here:
my code is as:-
enter code here
#include<iostream>
int main(){
const int i=10;
std::cout<<i<<"\n";
const_cast<int &>(i)=20;//trying to cast constantness of i.
std::cout<<i<<"\n";
}
This not giving me any error but the value of i is unchanged in output i.e.10. What mistake im performing in above code.
Aucun commentaire:
Enregistrer un commentaire