Division in c++
1. Change either of the two numbers 1 or 2 to a floating-point type. If one of the two operands is a floating-point type, the result is 0.5. as follows

int a = 1.0;

int b = 2;

The value of a/b is 0.5.

2, cast (float) or (double), the result is 0.5. as follows

int a = 5;

int b = 2;

The value of a/b is 2 (divisible), while the value of a/b double is 2.5.

The arithmetic operators in 1 and C++ include basic arithmetic operators and self-increasing and self-decreasing operators. An expression consisting of arithmetic operators, operands and parentheses is called an arithmetic expression.

2. The basic arithmetic operators are:+(addition),-(subtraction or minus sign), * (multiplication),/(division) and% (remainder). Where "-"is a unary operator when it is a minus sign, and the rest are binary operators. The meanings of these basic arithmetic operators are consistent with those of the corresponding symbols in mathematics. The relative priority relationship between them is also consistent with that in mathematics, that is, multiplication and division first, then addition and subtraction, and the same level operation from left to right. When using arithmetic operators, please note the following points:

(1)'%' is a remainder operation and can only be used for integer operands. The result of expression a%b is the remainder of a/B, and "%"and "/"have the same priority.

(2) When two integer operands are divided by "/",the integer part and the decimal part of the quotient are automatically discarded. Therefore, the result of the expression 1/2 is 0, which needs special attention.

(3) 3) The "++"(self-increasing) and "-"(self-decreasing) operators in C++are two convenient and efficient operators, both of which are unary operators. These two operators are used in both front and back forms.

References:

Baidu encyclopedia -c++