본문 바로가기
C#

증가 연산자와 감소 연산자 IncDec0perator

by JAESEONG LEE- developer 2022. 7. 18.

++ 연산자는 1씩 값을 증가시키고 -- 연산자는 1씩 값을 감소시킨다.

int a = 10;

a++; // 10으로 출력이 되지만 a는 11 이 된다. 

--a; // 10으로 a가 즉시 계산되고 출력된다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
 
namespace IncDec0perator
{
    class MainApp
    {
        static void Main(string[] args)
        {
            int a = 10;
            Console.WriteLine(a++);
            Console.WriteLine(++a);
 
            Console.WriteLine(a--);
            Console.WriteLine(--a);
        }
    }
}
cs

 

 

실행 결과입니다.