Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

Bitwise right-shift operator (>>)

The >> operator shifts bits right. Its result depends on the left operand's type and sign; the shift count must stay within the permitted range.

Version: C23; repository compiler flag, production runtime not attested

Syntax

value >> count

value >> count shifts bits right by count positions. Both operands must have integer types. Integer promotions apply; the result has the promoted left operand's type.

For unsigned or nonnegative values, the result is the integer part of division by 2^count. Unsigned shifts introduce zeros on the left. For negative signed values, the result is implementation-defined, including in C23.

A negative count, or one at least the promoted left operand's width, causes undefined behavior. In the example, 40u >> 3 yields 5; >> alone does not modify value.

Examples

#include <stdio.h>

int main(void)
{
    unsigned int value = 40u;
    unsigned int result = value >> 3;
    printf("%u\n", result);
    return 0;
}

Result

5

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources