加 (+)Addition (+)

加法运算符 (+) 导致添加其两个操作数。The addition operator (+) causes its two operands to be added. 两个操作数可同时为整型或浮点型,或者一个操作数为指针,另一个操作数为整数。Both operands can be either integral or floating types, or one operand can be a pointer and the other an integer.

在将整数添加到指针时,会通过将整数值 (i) 乘以指针寻址的值的大小来转换该整数值。When an integer is added to a pointer, the integer value (i) is converted by multiplying it by the size of the value that the pointer addresses. 转换后,整数值表示 i 个内存位置,其中每个位置均具有指针类型所指定的长度。After conversion, the integer value represents i memory positions, where each position has the length specified by the pointer type. 在将转换的整数值添加到指针值时,结果为表示原始地址中的地址 i 位置的新指针值。When the converted integer value is added to the pointer value, the result is a new pointer value representing the address i positions from the original address. 新指针值对类型与原始指针值的类型相同的值进行寻址,因此它与数组索引相同(请参阅一维数组多维数组)。The new pointer value addresses a value of the same type as the original pointer value and therefore is the same as array indexing (see One-Dimensional Arrays and Multidimensional Arrays). 如果 sum 指针指向数组的外部,除非位于在高端外的第一个位置,否则结果是不确定的。If the sum pointer points outside the array, except at the first location beyond the high end, the result is undefined. 有关详细信息,请参阅指针算法For more information, see Pointer Arithmetic.

另请参阅See Also

C 加法运算符C Additive Operators