hello guys i need help with this. im bit confused........
assuming a= 2 b= 3 c= 4 d= 5
why when i had if (!(d = 4) the output of d changes from 5 to 4? and why is this false??
1 2 3 4 5 6 7 8
if (!(d = 4))
{
cout << "If number 4 is true" << endl;
}
else
{
cout << "If number 4 is false" << endl;
}
d = 4 will assign the value 4 to the variable d and return the new value of d (4).
!(d = 4) -> !(4)
! is a logical operator that operates on bool values (true/false). If you use an integer where a bool is expected 0 will be treated as false and everything else will be treated as true.
!4 -> !true -> false
== compares if two values are equal. I bet that is what you want to use instead.