Header Ads

  • Breaking Now

    What is the difference between the '&' operator and the '&&' operator?

    '&&' is a Logical operator while '&' is a Bitwise operator.
    e.g.

    int x=12; binary represenation of 12---------> 1100
    int y=10; 1010 binary represenation of 10---------> 1010
    int z=x & y; binary represenation of (x & y)---------> 1000
    Here value of z will be 8.

    In case of logical operatior '&&':
    condition1 && condition2
    if condition1 is false then (condition1 && condition2) will always be false, that is the reason why this logical operator is also known as short circuit operator.
    if condition1 is true then condition2 is to be evaluated, if it is true then overall result will be true else it will be false.

    Post Top Ad

    Post Bottom Ad