i) What does if(0) mean?
Everytime I use it to test what output i will get, it returns the false part.
Is it equivalent to if(0 == 0), incase of which the true part is evaluated.
ii) Associativity of logical NOT ! is right to left.
Link: http://www.liv.ac.uk/HPC/HTMLF90Course/HTMLF90CourseNotesnode94.html
The second example in the link of logical operators:
But as per the line “the two subexpressions containing the monadic .NOT. are effectively evaluated first, as there are two of these the leftmost, .NOT.A is done first followed by .NOT.E.”, the left NOT is evaluated first, but the first one to be evaluated should be the one on the right…???
I) In C, 0 is false and everything else is true. So with
if (0), the condition will always be false and the body will never be executed because 0 is always false.if (0 == 0)is completely different because 0 does in fact equal zero, and the expression0 == 0evaluates to true, so the body of theifis executed.II) The associativity of operators determines what happens when you have ambiguities from multiple operators of the same precedence. For instance, what should happen in
a - b - c? Should theb - cbe evaluated first or thea - b? It does matter what order you do them in, because if a = 1, b = 2, and c = 3,a - (b - c)is2, but(a - b) - cis -4. But because subtraction is left-associative, we can know thata - bwill be evaluated first, so the answer toa - b - cis -4 when a = 1, b = 2, c = 3.All that being said, I can’t think of a case where the associativity of the logical not operator would matter, and the associativity of an operator does not determine what order it will be executed in when it is seperated by operators of different precedence.