How many iterations of the following loop will be performed?
 for(int x = 0; x = 3; x++); 
The assignment operator in C++ returns the value of the assignment to make chaining possible:
int a = b = c = 3;
After this assignment a, b, c will all be equal to 3. This line is also equal to
int a = (b = (c = 3));
In C++ assigning int to bool is made with implicit cast, and
bool b = (x = 3);
will result to 1. Thus the loop condition will always evaluate to true and we get infinite loop.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Зареєструйся Зараз
або Підпишись на майбутні тести