dimanche 20 janvier 2019

Is it possible to break constantness of constant value in c and c++? [duplicate]

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