Logical operations in C Why is 0x41 is 0x00 and why 0x41 is

Logical operations in C: Why is !0x41 is 0x00 and why !!0x41 is 0x01?

Solution

C provides a set of logical operators ||, &&, and !, which correspond to the OR, AND, and NOT operations of propositioal logic. The logical operations treat any nonzero argument as representing TRUE and argument 0 as respresenting FALSE. They return either 1 or 0 indicating a result of either TRUE or FALSE respectively.
Logical operators do not evaluate their second argument if the result of the expression can be determined by evaluating the first argument. Thus, for example, the expression a && 5/a will never cause a divison by zero, and the expression p && *p++ will never casue the dereferencing of a null pointer.

Examples of Char Datatype

!0x41 = 0x00

!0x00 = 0x01

!!0x41 = 0x01

Logical operations in C: Why is !0x41 is 0x00 and why !!0x41 is 0x01?SolutionC provides a set of logical operators ||, &&, and !, which correspond to th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site