% C · 运算符
取余运算符,返回整数相除后的余数。
怎么用
a % b
小例子
#include <stdio.h>
int main(void) {
printf("%d", 7 % 3);
return 0;
}
运行结果
输出 1
提醒:只能用于整数;除数不能为 0;浮点数取余用 fmod
官方文档:https://en.cppreference.com/w/c/language/operator_arithmetic
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条