c++ & operator
#include <iostream>
int main() {
int x = 5;
int y = 3;
int result = x & y;
std::cout << "Result: " << result << std::endl;
return 0;
}
Include the necessary header file
<iostream>
.Define the
main
function.Declare an integer variable
x
and initialize it with the value 5.Declare another integer variable
y
and initialize it with the value 3.Declare an integer variable
result
.Apply the bitwise AND operator (
&
) betweenx
andy
and assign the result to the variableresult
.Output the result using
std::cout
.Return 0 to indicate successful program execution.