0

please explain output

Hi #include <iostream> using namespace std; int main() { int x = 8; do { cout << x; }while(!-2); while(0); return 0; } I am getting output as 8....How? Specially what is syntax of !-2 in while loop.

9th Feb 2021, 3:36 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Answer
+ 3
Ketan Lalcheta Do while loop execute atleast once so output is 8 !-2 is not a syntax, as like !true and !false it's !-2 here !-2 returns 0 so it's do { cout << x; } while (0);
9th Feb 2021, 3:39 PM
A͢J
A͢J - avatar