I just wrote following code and it's working with g++. It shouldn't work. Why is it working?
#include <iostream>
using namespace std;
int main()
{
//char const *cstr;
const char *cstr;
char *cptr;
std::cin>>cptr;
cstr = cptr;
cstr = "CPP";
cout<<cstr;
return 0;
}
as it is apparent that cstr is const so it's modification in line cstr = "CPP"; should not work, but it is working. Why?