LoginSignup
0
0

More than 1 year has passed since last update.

インクリメント演算子(++)・デクリメント演算子(--)

Last updated at Posted at 2022-12-24

説明

変数の値に「1」を加算・減算するための演算子である。前置「++a」と後置「a++」がある。前置は、演算結果が代入されることに対し、後置は、元の値のコピーが戻されてから、変数の値が加算される。

public class Main {
	public static void main(String[] args) {
        
        //前置と後置の違い
        int a = 10;
        int b = ++a;//b = 1 + 10
        int c = a++;//c = 11 → a = 12
        
        int d = 10;
        int e = d++ + d + d-- - d-- + ++d;//10 + 11 + 11 -10 + 10
	}
}	
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0