使用加法运算符Using the Additive Operators

以下示例阐释了加法和减法运算符,它使用这些声明:The following examples, which illustrate the addition and subtraction operators, use these declarations:

int i = 4, j;  
float x[10];  
float *px;  

这些语句是等效的:These statements are equivalent:

px = &x[4 + i];  
px = &x[4] + i;    

i 的值乘以 float 的长度,再加上 &x[4]The value of i is multiplied by the length of a float and added to &x[4]. 结果指针值是 x[8] 的地址。The resulting pointer value is the address of x[8].

j = &x[i] - &x[i-2];  

在此示例中,用 x 的第五个元素的地址(由 x[i-2] 给定)减去 x 的第三个元素的地址(由 x[i] 给定)。In this example, the address of the third element of x (given by x[i-2]) is subtracted from the address of the fifth element of x (given by x[i]). float 的长度除以该差值;结果为整数值 2。The difference is divided by the length of a float; the result is the integer value 2.

另请参阅See Also

C 加法运算符C Additive Operators