+ 1

What does this code mean?

#include <iostream> using namespace std; int main() { int x=5; x=!(x>8); cout<<x; return 0; } why output is 1?

25th Nov 2016, 10:10 AM
MerzaT
MerzaT - avatar
6 odpowiedzi
+ 3
hi my friend ! attention : x>8 returns false ( that is 0 ) then NOT of false becomes true : !(false)= true so integer value of (true) is 1 and value of x becomes 1. (x=1) bye
25th Nov 2016, 10:30 AM
Amir Goodarzi
Amir Goodarzi - avatar
+ 1
دمت گرم داداش
25th Nov 2016, 10:32 AM
MerzaT
MerzaT - avatar
+ 1
output is 1 because x>8 is false and ! operater is logical not this to 1 x=not false that is x=true
25th Nov 2016, 11:06 AM
Sandeep Chatterjee
0
x>8 is a logical operation, but since x is an integer therefore logical results are displayed in form of 0 (means FALSE). Then the !0 becomes 1(means False). therefore output is 1.
25th Nov 2016, 12:22 PM
EDEEPAT
0
In x>8 if x=5 then 5>8.it becomes false. But not of false is true. When it is true it returns output 1.
25th Nov 2016, 3:24 PM
joffie
joffie - avatar
0
Included iostream; namespace std loaded; x = !(5>8); !(false) -- true, int cannot be transformed into bool */ 1
25th Nov 2016, 8:30 PM
undefinedVoid()
undefinedVoid() - avatar