ប្រមាណវិធីលើអថេរ(Operators)
Operators ត្រូវបានប្រើដើម្បីអនុវត្តការគណនាលើអថេរនិងតម្លៃ។
ក្នុងឧទាហរណ៍ខាងក្រោមយើងប្រើ សញ្ញា + ដើម្បីបន្ថែមតម្លៃពីររួមគ្នា៖
ឧទាហរណ៍
  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 ++ បែងចែក និមិត្តសញ្ញា ជាក្រុមដូចខាងក្រោមៈ
- Arithmetic operators
- Comparison operators
- Logical operators
- Bitwise operators
Arithmetic operators
Arithmetic Operators ត្រូវបានប្រើដើម្បីអនុវត្តគណិតវិទ្យាទូទៅដោយប្រើសញ្ញា(+ , - , * , / , %)។
| Name | Description | Example | |
|---|---|---|---|
| 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 | 
Assignment Operators
Assignment Operators ជាសញ្ញាប្រើសម្រាប់បញ្ជូនតម្លៃឫអោយតម្លៃ(= , += , -= , *= , /= , %=,.....)។
ក្នុងឧទាហរណ៍ខាងក្រោមយើងប្រើសញ្ញាស្មើរ ( = ) ដើម្បីកំណត់តម្លៃ ១០ ទៅអថេរមួយហៅថា x :
ឧទាហរណ៍
int x = 10; 
យើងប្រើសញ្ញាបូកស្មើ ( +=) បន្ថែមតម្លៃទៅអថេរមួយ៖
ឧទាហរណ៍
int x = 10;
x += 5; 
បញ្ជីនៃ Assignment Operators ទាំងអស់៖
| Example | Same As | |
|---|---|---|
| x = 5 | x = 5 | |
| x += 3 | x = x + 3 | |
| x -= 3 | x = x - 3 | |
| x *= 3 | x = x * 3 | |
| x /= 3 | x = x / 3 | |
| x %= 3 | x = x % 3 | |
| x &= 3 | x = x & 3 | |
| x |= 3 | x = x | 3 | |
| x ^= 3 | x = x ^ 3 | |
| x >>= 3 | x = x >> 3 | |
| x <<= 3 | x = x << 3 | 
Comparison Operators
Comparition Operators ត្រូវបានប្រើដើម្បីប្រៀបធៀបតម្លៃពីរ។
សម្គាល់ៈ តម្លៃត្រឡប់នៃការប្រៀបធៀបគឺពិត ( 1) ឬមិនពិត ( 0) ។
ក្នុងឧទាហរណ៍ខាងក្រោមយើងប្រើ សញ្ញាប្រមាណវិធី ធំជាង ( >) ដើម្បីដឹងថា ៥ ធំជាង ៣៖
ឧទាហរណ៍
  int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3 
បញ្ជី Comparition Operators ទាំងអស់៖
| Operator | Name | Example | 
|---|---|---|
| == | Equal to | x == y | 
| != | Not equal | x != y | 
| > | Greater than | x > y | 
| < | Less than | x < y | 
| >= | Greater than or equal to | x >= y | 
| <= | Less than or equal to | x <= y | 
Logical Operators
សញ្ញាប្រមាណវិធីឡូជីខល(ប្រមាណវិធីតក្ក)ត្រូវបានប្រើដើម្បីកំណត់តក្ករវាងអថេរឬតម្លៃ៖
| Operator | Name | Description | Example | 
|---|---|---|---|
| && | Logical and | Returns true if both statements are true | x < 5 && x < 10 | 
| || | Logical or | Returns true if one of the statements is true | x < 5 || x < 4 | 
| ! | Logical not | Reverse the result, returns false if the result is true | !(x < 5 && x < 10) | 
ការបញ្ចេញបញ្ចូលតម្លៃ (Input/Output)
C++ Output (Print Text)
cout<<ត្រូវបានប្រើដើម្បីតម្លៃទិន្នផល / អត្ថបទបោះពុម្ព:
ឧទាហរណ៍
  #include <iostream>
using namespace std;
int main() {
  
  cout << "Hello World!";
  return 0;
} 
User Input C ++
អ្នកបានដឹងរួចហើយថា coutវាត្រូវបានប្រើដើម្បីបង្កើតតម្លៃ (បោះពុម្ព) ។ ឥឡូវយើងនឹងប្រើ cinដើម្បីទទួលការបញ្ចូលពីអ្នកប្រើប្រាស់។
cinគឺជាអថេរដែលបានកំណត់ជាមុនដែលអានទិន្នន័យពីក្តារចុចជាមួយសញ្ញាស្រង់ចេញ ( >>) ។
ក្នុងឧទាហរណ៍ខាងក្រោមអ្នកប្រើអាចបញ្ចូលលេខដែលរក្សាទុកក្នុងអថេរ x។ បន្ទាប់មកយើងបោះពុម្ពតម្លៃនៃ x៖
ឧទាហរណ៍
  int x; 
cout << "Type a number: "; // Type a number and 
  press enter
cin >> x; // Get user 
  input from the keyboard
cout << "Your number is: " << x; 
  // Display the input value 
ល្អណាស់ដែលបានដឹង
coutត្រូវបានប្រកាសថា "មើលចេញ" ។ ប្រើសម្រាប់ លទ្ធផល និងប្រើសញ្ញាបញ្ចូល ( <<)
cinត្រូវបានប្រកាសថា "មើលក្នុង" ។ ប្រើសម្រាប់ បញ្ចូល និងប្រើសញ្ញាទាញយក ( >>)
ការបង្កើតម៉ាស៊ីនគណនាសាមញ្ញ
ក្នុងឧទាហរណ៍នេះអ្នកប្រើត្រូវតែបញ្ចូលពីរលេខ។ បន្ទាប់មកយើងព្រីនផលបូកដោយគណនា (បន្ថែម) ចំនួនពីរ៖
ឧទាហរណ៍
  int x, y;
int sum;
cout << "Type a number: ";
cin >> x;
cout << "Type another number: ";
cin >> 
  y;
sum = x + y;
cout << "Sum is: " << sum;អ្នកទៅ! 

