C++ 연산자
C++ 연산자
연산자는 변수와 값에 대한 연산을 수행하는 데 사용됩니다.
아래 예에서는
+
연산자 를 사용하여 두 값을 더합니다.
예시
int x = 100 + 50;
+
연산자는 위의 예와 같이 두 값을 더하는 데 자주 사용 되지만 변수와 값, 또는 변수와 다른 변수를 더하는 데 사용할 수도 있습니다.
예시
int sum1 = 100 + 50;
// 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400)
C++는 연산자를 다음 그룹으로 나눕니다.
산술 연산자
산술 연산자는 일반적인 수학 연산을 수행하는 데 사용됩니다.
Operator | Name | Description | Example | Try it |
---|---|---|---|---|
+ | Addition | Adds together two values | x + y | |
- | Subtraction | Subtracts one value from another | x - y | |
* | Multiplication | Multiplies two values | x * y | |
/ | Division | Divides one value by another | x / y | |
% | Modulus | Returns the division remainder | x % y | |
++ | Increment | Increases the value of a variable by 1 | ++x | |
-- | Decrement | Decreases the value of a variable by 1 | --x |