Operator precedence for comparison + + and +
1. Topics
Look at the code below and the result is:
/** * @Title: Calnum.java * @Package: Com.you.user.util * @Description: comparison operator Precedence * @author: Youhaidong (Zhanghaidong) * @date : 2014-7-23 PM 9:54:31 * @version V1.0 */package com.you.user.util;/** * Class function Description * Category Change Date * Change Note * <p>title:calnum.ja va</p> * <p>description: Zhanghaidong personal Development </p> * <p>copyright:copyright (c) 2013</p> * @author: 游海东 * @date: 2014-7-23 pm 9:54:31 * @version V1.0 */public class Calnum {/** * @Title: Main * @Description: * @param: @param args * @return: void * @throws */public static void Main (string[] args) {int i = 0;int result = ++i + i++ + ++i + i; SYSTEM.OUT.PRINTLN ("Result:" + result);}}
2. Analysis and explanation
(1) Results
Results: 8
(2) Analysis
First of all, whether it is ++i or i++. Their operation priority is higher than +, because I=0,++i. is first to I plus 1. Then participate in the operation, i++ is the first to participate in the operation, and then to I plus 1. This results in result = 1 + 1 + 3 + 3. The result of the calculation is 8
Operator precedence for comparison + + and +