एक ऑपरेटर एक प्रतीक है जो संकलक को विशिष्ट गणितीय या तार्किक जोड़तोड़ करने के लिए कहता है।
| संचालक | विवरण | उदाहरण |
|---|---|---|
| + | दो ऑपरेंड जोड़ता है | A + B =30 |
| - | दूसरे ऑपरेंड को पहले से घटाता है | A - B =-10 |
| * | दोनों ऑपरेंड को गुणा करता है | ए * बी =200 |
| / | अंश को अंश से विभाजित करता है | बी / ए =2 |
| % | मॉड्यूलस ऑपरेटर और एक पूर्णांक विभाजन के बाद का शेष | B % A =0 |
| ++ | इन्क्रीमेंट ऑपरेटर पूर्णांक मान को एक से बढ़ाता है | A++ =11 |
| -- | डिक्रीमेंट ऑपरेटर पूर्णांक मान को एक से घटा देता है | A-- =9 |
आइए सी#में अंकगणितीय ऑपरेटरों का उपयोग करने के लिए एक उदाहरण देखें।
उदाहरण
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int a = 99;
int b = 33;
int c;
c = a + b;
Console.WriteLine("Value of c is {0}", c);
c = a - b;
Console.WriteLine("Value of c is {0}", c);
c = a * b;
Console.WriteLine("Value of c is {0}", c);
c = a / b;
Console.WriteLine("Value of c is {0}", c);
c = a % b;
Console.WriteLine("Value of c is {0}", c);
c = a++;
Console.WriteLine("Value of c is {0}", c);
c = a--;
Console.WriteLine("Value of c is {0}", c);
Console.ReadLine();
}
}
} आउटपुट
Value of c is 132 Value of c is 66 Value of c is 3267 Value of c is 3 Value of c is 0 Value of c is 99 Value of c is 100