Predict the output:
#include <iostream>
using namespace std;
int main()
{
int x = -5;
x = x >> 1;
cout << x << endl;
return 0;
}
#include <stdio.h>
int main() {
int x = -5;
x = x >> 1;
printf("%d\n", x);
return 0;
}
public class Main {
public static void main(String[] args) {
int x = -5;
x = x >> 1;
System.out.println(x);
}
}
# x is initialized to -5
x = -5
# Right shift operation
x = x >> 1
# Print the result
print(x)
// x is initialized to -5
let x = -5;
// Right shift operation
x = x >> 1;
// Print the result
console.log(x);
-2
-3
Error
-1
This question is part of this quiz :
Top MCQs on Bitwise Algorithms and Bit Manipulations with Answers