Top | MCQs on Bitwise Algorithms and Bit Manipulations with Answers | Question 24

Last Updated :
Discuss
Comments

Predict the output:

C++
#include <iostream>
using namespace std;

int main()
{
    int x = -5;
    x = x >> 1;
    cout << x << endl;
    return 0;
}
C
#include <stdio.h>

int main() {
    int x = -5;
    x = x >> 1;
    printf("%d\n", x);
    return 0;
}
Java
public class Main {
    public static void main(String[] args) {
        int x = -5;
        x = x >> 1;
        System.out.println(x);
    }
}
Python
# x is initialized to -5
x = -5
# Right shift operation
x = x >> 1
# Print the result
print(x)
JavaScript
// x is initialized to -5
let x = -5;
// Right shift operation
x = x >> 1;
// Print the result
console.log(x);

-2

-3

Error

-1

Share your thoughts in the comments