I have read that following code would be invalid and should issue error:
double rates[5] = {88.99, 100.12, 59.45, 183.11, 340.5};
const double locked[4] = {0.08, 0.075, 0.0725, 0.07};
double * pnc = rates; // valid
pnc = locked; // not valid
pnc = &rates[3]; // valid
pnc
is pointer-to-double and user can't change data through it. Although, I compiled program adding this chunk of code:
printf("%f\n", *pnc);
*pnc = 1000.0;
printf("%f\n", *pnc);
Visual Studio Community gave me warning C4090 (different 'const' qualifiers), but executed without problems. When I run program, output looks like this:
0.080000
1000.000000
Why can I do it even in case it has to be forbidden?