Q:

Which of the following are legal? For those that are illegal, explain why

0

Which of the following are legal? For those that are illegal, explain why.

(a) const int buf;
(b) int cnt = 0;
(c) const int sz = cnt;
(d) ++cnt; ++sz;

All Answers

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

int main() {
  //const int buf;       // Error: must be initialized
  int cnt = 0;         // OK
  const int sz = cnt;  // OK
  ++cnt;  // OK
  //++sz;   // Error: cannot change the value of 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