Cpp-Primer
Cpp-Primer copied to clipboard
exercise 2.29
p2 = p1; // illegal. p2 is a const pointer. ic = *p3; // illegal. ic is a const int. I think that two answers are legal,not illegal,beacuse I can run them in TMD gcc-4.92
paste the code please?
I tried the following code and got error from compiler
int main() {
int i, *const cp = &i;
int *p1, *const p2 = p1;
const int ic = 5, &r = ic;
const int *const p3 = ⁣
const int *p;
i = ic; // OK
p1 = p3; // Error: low-level const doesn't match
p1 = ⁣ // Error: low-level const doesn't match
p3 = ⁣ // Error: cannot assign value to a const variable
p2 = p1; // Error: cannot assign value to a const variable
ic = *p3; // Error: cannot assign value to a const variable
return 0;
}