I tested the program using static allocation and the compiler gives me an error when I had changed the value .
But when I used dynamic allocation, the value changed .
class Test{
private:
int *value;
public:
Test( int v ){
value = new int;
*value = v;
}
int getValue() const{
*value = 110;
return *value;
}
~Test(){
delete value;
}
};
int main(){
Test t1(7);
cout<<t1.getValue()<<endl;
}