What does the '%' operator mean?

后端 未结 11 1765
执笔经年
执笔经年 2020-12-11 18:28

I have next code

int a,b,c;
b=1;
c=36;
a=b%c;

What does \"%\" operator mean?

11条回答
  •  一个人的身影
    2020-12-11 18:59

    % is the remainder operator in many C-inspired languages.

    3 % 2 == 1
    789 % 10 = 9
    

    It's a bit tricky with negative numbers. In e.g. Java and C#, the result has the same sign as the dividend:

    -1 % 2 == -1
    

    In e.g. C++ this is implementation defined.

    See also

    • Wikipedia/Modulo operation

    References

    • MSDN/C# Language Reference/% operator

提交回复
热议问题