Share c++ operator

viendonghuynh

New member
#C ++ #Operator #Programming #Coding #tutorial

## c ++ toán tử

Các nhà khai thác là các biểu tượng đặc biệt thực hiện các hoạt động trên toán hạng.Các toán hạng có thể là các biến, hằng số hoặc biểu thức.Kết quả của một hoạt động được gọi là giá trị ** ** của biểu thức.

C ++ có một bộ toán tử phong phú, bao gồm các toán tử số học, logic, quan hệ và bitwise.

### Các toán tử số học

Các toán tử số học được sử dụng để thực hiện các hoạt động toán học trên các toán hạng.Bảng sau liệt kê các toán tử số học trong C ++:

|Nhà điều hành |Biểu tượng |Mô tả |
| --- | --- | --- |
|Bổ sung |+ |Thêm các toán hạng |
|Phép trừ |- |Trừ toán hạng thứ hai từ lần đầu tiên |
|Phép nhân |* |Nhân các toán hạng |
|Sư đoàn |/ |Chia toán hạng thứ nhất cho lần thứ hai |
|Mô đun |% |Trả về phần còn lại của bộ phận của toán hạng đầu tiên theo thứ hai |

### toán tử logic

Các toán tử logic được sử dụng để so sánh các toán hạng và trả về giá trị boolean là `true` hoặc` false '.Bảng sau liệt kê các toán tử logic trong C ++:

|Nhà điều hành |Biểu tượng |Mô tả |
| --- | --- | --- |
|Và |&& |Trả về `true` nếu cả hai toán hạng là` true` |
|Hoặc ||||Trả về `true` nếu một trong hai toán hạng là` true` |
|Không |!!|Trả về `true` nếu toán hạng là` false` |

### Các nhà khai thác quan hệ

Các toán tử quan hệ được sử dụng để so sánh các toán hạng và trả về giá trị boolean của `true` hoặc` false '.Bảng sau liệt kê các toán tử quan hệ trong C ++:

|Nhà điều hành |Biểu tượng |Mô tả |
| --- | --- | --- |
|Bằng |== |Trả về `true` nếu các toán hạng bằng nhau |
|Không bằng |! = |Trả về `true` nếu các toán hạng không bằng nhau |
|Lớn hơn |> |Trả về `true` nếu toán hạng đầu tiên lớn hơn lần thứ hai |
|Ít hơn |<|Trả về `true` nếu toán hạng đầu tiên nhỏ hơn lần thứ hai |
|Lớn hơn hoặc bằng |> = |Trả về `true` nếu toán hạng đầu tiên lớn hơn hoặc bằng với phần thứ hai |
|Nhỏ hơn hoặc bằng |<= |Trả về `true` nếu toán hạng đầu tiên nhỏ hơn hoặc bằng với thứ hai |

### Các toán tử bitwise

Các toán tử bitwise được sử dụng để thực hiện các hoạt động bitwise trên các toán hạng.Bảng sau liệt kê các toán tử bitwise trong C ++:

|Nhà điều hành |Biểu tượng |Mô tả |
| --- | --- | --- |
|Và |& |Thực hiện một chút và hoạt động |
|Hoặc |\ ||Thực hiện một chút hoặc hoạt động |
|Xor |^ |Thực hiện thao tác XOR bitwise |
|Không |~ |Thực hiện một chút không hoạt động |
|SHIF trái |<< |Dịch chuyển các bit của toán hạng đầu tiên để lại số lượng bit được chỉ định bởi toán hạng thứ hai |
|Đúng sự thay đổi |>> |Dịch chuyển các bit của toán hạng đầu tiên ngay theo số lượng bit được chỉ định bởi toán hạng thứ hai |

### Ưu tiên điều hành

Thứ tự mà các toán tử được đánh giá được gọi là ưu tiên toán tử.Bảng sau đây liệt kê được người vận hành ưu tiên trong C ++:

|Nhà điều hành |Ưu tiên |
| --- | --- |
|!!|1 |
|~ |1 |
|++ |2 |
|- |2 |
|() |3 |
|-> |3 |
|* |4 |
|/ |4 |
|% |4 |
|+ |5 |
|- |5 |
|<< |6 |
|>> |6 |
|<|7 |
|> |7 |
|<= |7 |
|> = |7 |
|== |8 |
|! = |8 |
|& |9 |
|^ |10 |
|\ ||11 |
|&& |12 |
||||13 |

## Ví dụ

Mã sau đây hiển thị một ví dụ về việc sử dụng các toán tử trong C ++:

`` `C ++
#
=======================================
#C++ #Operator #Programming #Coding #tutorial

## C++ Operators

Operators are special symbols that perform operations on operands. The operands can be variables, constants, or expressions. The result of an operation is called the **value** of the expression.

C++ has a rich set of operators, including arithmetic, logical, relational, and bitwise operators.

### Arithmetic Operators

The arithmetic operators are used to perform mathematical operations on operands. The following table lists the arithmetic operators in C++:

| Operator | Symbol | Description |
|---|---|---|
| Addition | + | Adds the operands |
| Subtraction | - | Subtracts the second operand from the first |
| Multiplication | * | Multiplies the operands |
| Division | / | Divides the first operand by the second |
| Modulus | % | Returns the remainder of the division of the first operand by the second |

### Logical Operators

The logical operators are used to compare operands and return a Boolean value of `true` or `false`. The following table lists the logical operators in C++:

| Operator | Symbol | Description |
|---|---|---|
| AND | && | Returns `true` if both operands are `true` |
| OR | || | Returns `true` if either operand is `true` |
| NOT | ! | Returns `true` if the operand is `false` |

### Relational Operators

The relational operators are used to compare operands and return a Boolean value of `true` or `false`. The following table lists the relational operators in C++:

| Operator | Symbol | Description |
|---|---|---|
| Equal to | == | Returns `true` if the operands are equal |
| Not equal to | != | Returns `true` if the operands are not equal |
| Greater than | > | Returns `true` if the first operand is greater than the second |
| Less than | < | Returns `true` if the first operand is less than the second |
| Greater than or equal to | >= | Returns `true` if the first operand is greater than or equal to the second |
| Less than or equal to | <= | Returns `true` if the first operand is less than or equal to the second |

### Bitwise Operators

The bitwise operators are used to perform bitwise operations on operands. The following table lists the bitwise operators in C++:

| Operator | Symbol | Description |
|---|---|---|
| AND | & | Performs a bitwise AND operation |
| OR | \| | Performs a bitwise OR operation |
| XOR | ^ | Performs a bitwise XOR operation |
| NOT | ~ | Performs a bitwise NOT operation |
| Left shift | << | Shifts the bits of the first operand left by the number of bits specified by the second operand |
| Right shift | >> | Shifts the bits of the first operand right by the number of bits specified by the second operand |

### Operator Precedence

The order in which operators are evaluated is called operator precedence. The following table lists the operator precedence in C++:

| Operator | Precedence |
|---|---|
| ! | 1 |
| ~ | 1 |
| ++ | 2 |
| -- | 2 |
| () | 3 |
| -> | 3 |
| * | 4 |
| / | 4 |
| % | 4 |
| + | 5 |
| - | 5 |
| << | 6 |
| >> | 6 |
| < | 7 |
| > | 7 |
| <= | 7 |
| >= | 7 |
| == | 8 |
| != | 8 |
| & | 9 |
| ^ | 10 |
| \| | 11 |
| && | 12 |
| || | 13 |

## Example

The following code shows an example of using operators in C++:

```c++
#
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top