Download presentation
Presentation is loading. Please wait.
1
Operator and Expression
I –Operators Operators ជាអ្វី? តើប្រើវាដើម្បីអ្វី? តើ operators មានអ្វីខ្លះ?
2
Operator and Expression
Binary operator/Arithmetic operator + : addition - : subtraction * : multiplication / : division % : modulus
3
Operator and Expression
នៅក្នុងភាសា C++ សញ្ញា % ត្រូវបានប្រើតែលើចំនួនគត់ប៉ុណ្ណោះ។ ចំពោះសញ្ញា / ផលចែកនឹងទទួលបានចំនួនគត់ បើសិនជាយើងធ្វើប្រមាណវិធី ចំនួនគត់ និងចំនួនគត់។ អាទិភាពក្នុង arithmetic operator ប្រមាណវិធីត្រូវបានអនុវត្តន៍ពីឆ្វេងមកស្តាំ ។ប្រមាណវិធី (/, *, %) មានអាទិភាពស្មើគ្នា តែប្រមាណវិធីទាំងបីនេះមានអាទិភាពខ្ពស់ជាងប្រមាណវិធី (+, -) ។
4
Operator and Expression
2+8/3=? 4/2-10=? 8*3/2=? 2+8.0/3=? 5-1%2=? (4-1)%2=?
5
Operator and Expression
2+8/3 =4 4/2-10 =-8 8*3/2 =12 2+8.0/ = 3-1%2 =2 (3-1)%2 =0 ដើម្បីបញ្ជាក់ពីអាទិភាពនៃប្រមាណវិធីណាមួយយើងត្រូវប្រើសញ្ញា ( ) ក្តោបតម្លៃនោះជាកន្សោម។ឧទាហរណ៍ (3-1)%2 ។
6
Operator and Expression
2. Assignment operator = : assign to += : compound addition -= : compound subtraction %= : compound modulation *= : compound multiplication /= : compound division int x=10; x+=1; printf(“%d”, x); //output: 11 int x=10; x/=2; printf(“%d”, x); //output: 5
7
Operator and Expression
3. Unary operator ++ : increment : decrement int x=10; x++; //x=x+1; or x+=1; printf(“%d”, x); //output: 11 int x=10; printf(“%d”, x); //output: 10 int x=10; ++x; printf(“%d”, x); //output: 11 int x=10; printf(“%d”, x); //output: 11
8
Operator and Expression
4. Comparison operator /Relational operator < : less than > : greater than <= : less than or equal to >= : greater than or equal to != : not equal to == : equal to printf(“%d”, 3==3); //output: 1 printf (“%d”, 5<=6); //output: 1 printf (“%d”, 3<=2); //output: 0 printf (“%d”, 4!=5); //output: 1
9
Operator and Expression
5. Logical operator && : AND operator || : OR operator ! : NOT operator ^ : EXCLUSIVE OR operator int x=10; printf("%d", (x==10)&& (x>11)); //output: 0 bool x=false; printf("%d", !x); //output =1 int x=10; printf("%d", (x==10) || (x>11); //output:1 bool b=false; printf (“%d”, (0==1^1<2)); //output: 1
10
Operator and Expression
II. Expression Expression ជាបណ្តុំនៃ operands និងoperators ដែលត្រូវបានប្រើប្រាស់សម្រាប់គណនារកតម្លៃណាមួយពី operands។គ្រប់ expression ត្រូវមាន យ៉ាងហោចណាស់ 1 operand។ Operand ជាតម្លៃ រីឯ operator ជាសញ្ញាសម្រាប់ធ្វើប្រមាណវិធី។ x=2; y=x+2; (100==100) A!=a (a<b)&&(a>c) x<y||x!=y operator: + y=x+2; operand: x, y constant: 2
11
សំនួរ
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.