Q:

Uing the variables in the previous exercise, which of the following assignments are legal? Explain why

0

Using the variables in the previous exercise, which of the following assignments are legal? Explain why

(a) i = ic;
(b) p1 = p3;
(c) p1 = ⁣
(d) p3 = ⁣
(e) p2 = p1;
(f) ic = *p3;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now