Single Choice Easy

QWhat is the value of m &= 5 after the expression is executed in Java? (m = 10)

ID: #20161 Assignment Operators Java 105 views
Question Info
#20161Q ID
EasyDifficulty
Assignment Operators JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 0
  • B 1
  • C 5
  • D 10
Correct Answer

Explanation

In Java, the expression m &= 5 is a compound assignment operator that performs a bitwise AND between the variable m and the value 5. It is equivalent to the expression m = m & 5.

Here's an example in Java:


public class CompoundAssignmentExample {
    public static void main(String[] args) {
        // Declare variables
        int m = 10;

        // Compound assignment (bitwise AND with 5)
        m &= 5;

        // Display the result
        System.out.println("The value of m after m &= 5 is: " + m);
    }
}

In this example, if m is initially 10, after the operation, the value of m will be 0. This is because the binary representation of 10 is 1010, and performing a bitwise AND with 5 (binary 0101) results in 0000, which is 0 in decimal.

Share This Question

Challenge a friend or share with your study group.