-3
bool ok =true;
ok &= (a[i] - a[i - 1] <= 1);

1.whats the "&" means in this code? 2.Is it assignment of any variable?

  • 3
    Are you having a problem locating the chapter in your C++ textbook which explains this, and other operators? Which C++ textbook are you using? – Sam Varshavchik Aug 18 '20 at 16:52
  • Once you read up on `&`, you'll discover that it's a waste of time here: the code above could easily be rewritten as `bool ok = (a[i] - a[i - 1] <= 1);` – Caleb Aug 18 '20 at 17:06

1 Answers1

0

In this context, &= is the bitwise AND-assignment operator. The value of the variable on the lefthand side (ok) is AND'ed with the value of the expression on the righthand side ((a[i] - a[i - 1] <= 1)), and the result is then assigned back to the lefthand variable.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770