Cpp-Primer icon indicating copy to clipboard operation
Cpp-Primer copied to clipboard

exercise 2.29

Open wallcwr opened this issue 5 years ago • 1 comments

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

wallcwr avatar Aug 25 '19 10:08 wallcwr

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;
}

ytf4425 avatar Aug 24 '22 16:08 ytf4425