if you want to remove an article from website contact us from top.

    in a program, which of the following is a logical operator that returns true if and only if both of its operands are true?

    Mohammed

    Guys, does anyone know the answer?

    get in a program, which of the following is a logical operator that returns true if and only if both of its operands are true? from screen.

    LOGICAL Operators and Expressions

    LOGICAL Operators and Expressions

    Fortran has five LOGICAL operators that can only be used with expressions whose results are logical values (, .TRUE. or .FALSE.). All LOGICAL operators have priorities lower than and operators. Therefore, if an expression involving arithmetic, relational and logical operators, the arithmetic operators are evaluated first, followed by the relational operators, followed by the logical operators.

    These five logical operators are

    .NOT. : logical not.AND. : logical and.OR. : logical or.EQV. : logical equivalence.NEQV. : logical not equivalence

    The following is a table of these operators, including there priority and associativity.

    Arithmetic ** right to left* / left to right+ - left to rightRelational < <= > >= == /= noneLogical .NOT. right to left.AND. left to right.OR. left to right.EQV. .NEQV. left to right

    Truth Tables

    The evaluation of logical expressions is determined by truth tables. Let us start with the .NOT. operator.

    .NOT. Operand Result.TRUE. .FALSE..FALSE. .TRUE.

    Note that .NOT. is a unary operator. Therefore, .NOT. a yields .TRUE. (, .FALSE.) if the value of LOGICAL variable a is .FALSE. (, .TRUE.).

    The following is the truth table of .AND.:

    .AND. .TRUE. .FALSE.TRUE. .TRUE. .FALSE..FALSE. .FALSE. .FALSE.

    Therefore, the result of logical expression a .AND. b is .TRUE. if and only if both operands a and b are .TRUE.. In all other cases, the result is always .FALSE.

    The following is the truth table of .OR.:

    .OR. .TRUE. .FALSE.TRUE. .TRUE. .TRUE..FALSE. .TRUE. .FALSE.

    Therefore, the result of logical expression a .OR. b is .FALSE. if and only if both operands a and b are .FALSE.. In all other cases, the result is always .TRUE. In other words, if one of the two operands of the .OR. operator is .TRUE., the result is .TRUE.

    The following is the truth table of .EQV.:

    .EQV. .TRUE. .FALSE.TRUE. .TRUE. .FALSE..FALSE. .FALSE. .TRUE.

    Therefore, the result of logical expression a .EQV. b is .TRUE. if and only if both operands a and b have the same value (, both are .TRUE. or both are .FALSE.). As mentioned in expressions, relational operators can only compare arithmetic values and cannot be used to compare logical values. To compare if two logical values are equal, use .EQV.

    The following is the truth table of .NEQV.:

    .NEQV. .TRUE. .FALSE.TRUE. .FALSE. .TRUE..FALSE. .TRUE. .FALSE.

    Therefore, the result of logical expression a .NEQV. b is .TRUE. if and only if both operands a and b do not have the same value. As mentioned in expressions, relational operators can only compare arithmetic values and cannot be used to compare logical values. To compare if two logical values are not equal, use .NEQV. Note that .NEQV is the opposite of .EQV.. Hence, to test if logical variables x and y have different values, one can use .NOT. (x .EQV. y). Here, if x and y have the same value, x .EQV. y is .TRUE. and .NOT. (x .EQV. y) is .FALSE. On the other hand, if x and y have different values, x .EQV. y is .FALSE. and .NOT. (x .EQV. y) is .TRUE.

    Priority

    The priority of .NOT. is the highest, followed by .AND., followed by .OR., followed by .EQV. and .NEQV. Note that .NOT. is right associative, while the other four are left associative.

    Here are some examples:

    Let LOGICAL variables Something and Another have values .TRUE. and .FALSE., respectively.

    .NOT. Something .AND. Another

    --> .NOT. .TRUE. .AND. .FALSE.

    --> [.NOT. .TRUE.] .AND. .FALSE.

    --> .FALSE. .AND. .FALSE.

    --> .FALSE.

    In the above, since .NOT. has the highest priority, it is evaluated first. Now, look at the following example:

    .NOT. (Something .AND. Another)

    --> .NOT. (.TRUE. .AND. .FALSE.)

    --> .NOT. ([.TRUE. .AND. .FALSE.])

    --> .NOT. .FALSE. --> .TRUE.

    Let LOGICAL variables a, b and c have values .TRUE., .TRUE. and .FALSE., respectively.

    .NOT. a .OR. .NOT. b .AND. c

    --> .NOT. .TRUE. .OR. .NOT. .TRUE. .AND. .FALSE.

    --> [.NOT. .TRUE.] .OR. .NOT. .TRUE. .AND. .FALSE.

    --> .FALSE. .OR. .NOT. .TRUE. .AND. .FALSE.

    --> .FALSE. .OR. [.NOT. .TRUE.] .AND. .FALSE.

    --> .FALSE. .OR. .FALSE. .AND. .FALSE.

    --> .FALSE. .OR. [.FALSE. .AND. .FALSE.]

    --> .FALSE. .OR. .FALSE.

    --> .FALSE.

    Let INTEGER variable n have a value of 4:

    स्रोत : pages.mtu.edu

    Boolean logical operators

    C# logical operators perform logical negation (`!`), conjunction (AND - `&`, `&&`), and inclusive and exclusive disjunction (OR - `|`, `||`, `^`) operations with Boolean operands.

    We use optional cookies to improve your experience on our websites, such as through social media connections, and to display personalized advertising based on your online activity. If you reject optional cookies, only cookies necessary to provide you the services will be used. You may change your selection by clicking “Manage Cookies” at the bottom of the page. Privacy Statement Third-Party Cookies

    Boolean logical operators - AND, OR, NOT, XOR

    Article 12/02/2022 7 minutes to read

    The logical Boolean operators perform logical operations with bool operands. The operators include the unary logical negation (!), binary logical AND (&), OR (|), and exclusive OR (^), and the binary conditional logical AND (&&) and OR (||).

    Unary ! (logical negation) operator.

    Binary & (logical AND), | (logical OR), and ^ (logical exclusive OR) operators. Those operators always evaluate both operands.

    Binary && (conditional logical AND) and || (conditional logical OR) operators. Those operators evaluate the right-hand operand only if it's necessary.

    For operands of the integral numeric types, the &, |, and ^ operators perform bitwise logical operations. For more information, see Bitwise and shift operators.

    Logical negation operator !

    The unary prefix ! operator computes logical negation of its operand. That is, it produces true, if the operand evaluates to false, and false, if the operand evaluates to true:

    bool passed = false;

    Console.WriteLine(!passed); // output: True

    Console.WriteLine(!true); // output: False

    The unary postfix ! operator is the null-forgiving operator.

    Logical AND operator &

    The & operator computes the logical AND of its operands. The result of x & y is true if both x and y evaluate to true. Otherwise, the result is false.

    The & operator evaluates both operands even if the left-hand operand evaluates to false, so that the operation result is false regardless of the value of the right-hand operand.

    In the following example, the right-hand operand of the & operator is a method call, which is performed regardless of the value of the left-hand operand:

    bool SecondOperand()

    {

    Console.WriteLine("Second operand is evaluated.");

    return true; }

    bool a = false & SecondOperand();

    Console.WriteLine(a);

    // Output:

    // Second operand is evaluated.

    // False

    bool b = true & SecondOperand();

    Console.WriteLine(b);

    // Output:

    // Second operand is evaluated.

    // True

    The conditional logical AND operator && also computes the logical AND of its operands, but doesn't evaluate the right-hand operand if the left-hand operand evaluates to false.

    For operands of the integral numeric types, the & operator computes the bitwise logical AND of its operands. The unary & operator is the address-of operator.

    Logical exclusive OR operator ^

    The ^ operator computes the logical exclusive OR, also known as the logical XOR, of its operands. The result of x ^ y is true if x evaluates to true and y evaluates to false, or x evaluates to false and y evaluates to true. Otherwise, the result is false. That is, for the bool operands, the ^ operator computes the same result as the inequality operator !=.

    Console.WriteLine(true ^ true); // output: False

    Console.WriteLine(true ^ false); // output: True

    Console.WriteLine(false ^ true); // output: True

    Console.WriteLine(false ^ false); // output: False

    For operands of the integral numeric types, the ^ operator computes the bitwise logical exclusive OR of its operands.

    Logical OR operator |

    The | operator computes the logical OR of its operands. The result of x | y is true if either x or y evaluates to true. Otherwise, the result is false.

    The | operator evaluates both operands even if the left-hand operand evaluates to true, so that the operation result is true regardless of the value of the right-hand operand.

    In the following example, the right-hand operand of the | operator is a method call, which is performed regardless of the value of the left-hand operand:

    bool SecondOperand()

    {

    Console.WriteLine("Second operand is evaluated.");

    return true; }

    bool a = true | SecondOperand();

    Console.WriteLine(a);

    // Output:

    // Second operand is evaluated.

    // True

    bool b = false | SecondOperand();

    Console.WriteLine(b);

    // Output:

    // Second operand is evaluated.

    // True

    The conditional logical OR operator || also computes the logical OR of its operands, but doesn't evaluate the right-hand operand if the left-hand operand evaluates to true.

    For operands of the integral numeric types, the | operator computes the bitwise logical OR of its operands.

    Conditional logical AND operator &&

    The conditional logical AND operator &&, also known as the "short-circuiting" logical AND operator, computes the logical AND of its operands. The result of x && y is true if both x and y evaluate to true. Otherwise, the result is false. If x evaluates to false, y isn't evaluated.

    In the following example, the right-hand operand of the && operator is a method call, which isn't performed if the left-hand operand evaluates to false:

    bool SecondOperand()

    {

    Console.WriteLine("Second operand is evaluated.");

    स्रोत : learn.microsoft.com

    Logical AND operator &&

    IBM Documentation.

    Logical AND operator &&

    Last Updated: 2022-01-21

    The && (logical AND) operator indicates whether both operands are true.

    If both operands have nonzero values, the result has the value 1. Otherwise, the result has the value 0. The type of the result is int. Both operands must have an arithmetic or pointer type. The usual arithmetic conversions on each operand are performed.

    If both operands have values of true, the result has the value true. Otherwise, the result has the value false. Both operands are implicitly converted to bool and the result type is bool.

    Unlike the & (bitwise AND) operator, the && operator guarantees left-to-right evaluation of the operands. If the left operand evaluates to 0 (or false), the right operand is not evaluated.

    The following examples show how the expressions that contain the logical AND operator are evaluated:

    Expression Result 1 && 0 false or 0 1 && 4 true or 1 0 && 0 false or 0

    The following example uses the logical AND operator to avoid division by zero:

    (y != 0) && (x / y)

    The expression x / y is not evaluated when y != 0 evaluates to 0 (or false).

    Note: The logical AND (&&) should not be confused with the bitwise AND (&) operator. For example:

    1 && 4 evaluates to 1 (or    true)

    while

    1 & 4 evaluates to 0

    स्रोत : www.ibm.com

    Do you want to see answer or more ?
    Mohammed 9 day ago
    4

    Guys, does anyone know the answer?

    Click For Answer