Home > Article > Backend Development > The difference between / and % in C language
The difference between '/' and '%' operators in C language: '/' is the division operator, used to calculate the quotient. '%' is the modulo operator used to calculate the remainder. The divisor must be a positive integer, and the dividend can be a positive or negative integer.
The difference between / and % in C language
In C language, '/'
and '%'
are two different operators used for different purposes:
1. /
(division operator)
'/'
is the division operator used to calculate the quotient of two numbers. 2. %
(modulo operator)
'%'
is Modulo operator, used to calculate the remainder of two integers. Example:
Division operation:
<code class="c">int a = 10; int b = 3; int result = a / b; // result = 3 (整数除法)</code>
Modulo operation:
<code class="c">int a = 10; int b = 3; int result = a % b; // result = 1 (余数)</code>
Note:
The above is the detailed content of The difference between / and % in C language. For more information, please follow other related articles on the PHP Chinese website!