Arithmetic operators are used to perform common mathematical operations.
Operator |
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-- |
1. Addition Operator (+)
The addition operator adds two operands.
int a = 10;
int b = 20;
int sum = a + b; // sum is 30
double x = 5.5;
double y = 2.5;
double result = x + y; // result is 8.0
2 . Subtraction Operator (-)
The subtraction operator subtracts the second operand from the first.
int a = 20;
int b = 10;
int difference = a - b; // difference is 10
double x = 5.5;
double y = 2.5;
double result = x - y; // result is 3.0
3 . Multiplication Operator (*)
int a = 10;
int b = 20;
int product = a * b; // product is 200
double x = 5.5;
double y = 2.0;
double result = x * y; // result is 11.0
4. Division Operator (/)
The division operator divides the first operand by the second. If both operands are integers, the result is an integer (fractional part is discarded).
int a = 20;
int b = 10;
int quotient = a / b; // quotient is 2
double x = 5.5;
double y = 2.0;
double result = x / y; // result is 2.75
5. Modulus Operator (%)
The modulus operator returns the remainder of the division of the first operand by the second.
int a = 20;
int b = 7;
int remainder = a % b; // remainder is 6
double x = 5.5;
double y = 2.0;
double result = x % y; // result is 1.5
Increment and Decrement Operators
While not strictly arithmetic operators, increment and decrement operators are commonly used in arithmetic contexts.
6. Increment Operator (++)
The increment operator increases an integer value by one.
int a = 10;
a++; // a is now 11
double x = 5.5;
x++; // x is now 6.5
7. Decrement Operator (--)
The decrement operator decreases an integer value by one.
int a = 10;
a--; // a is now 9
double x = 5.5;
x--; // x is now 4.5
Arithmetic operators are used to perform common mathematical operations.
Operator |
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-- |
1. Addition Operator (+)
The addition operator adds two operands.
int a = 10; int b = 20; int sum = a + b; // sum is 30 double x = 5.5; double y = 2.5; double result = x + y; // result is 8.0
2 . Subtraction Operator (-)
The subtraction operator subtracts the second operand from the first.
int a = 20; int b = 10; int difference = a - b; // difference is 10 double x = 5.5; double y = 2.5; double result = x - y; // result is 3.0
3 . Multiplication Operator (*)
int a = 10; int b = 20; int product = a * b; // product is 200 double x = 5.5; double y = 2.0; double result = x * y; // result is 11.0
4. Division Operator (/)
The division operator divides the first operand by the second. If both operands are integers, the result is an integer (fractional part is discarded).
int a = 20; int b = 10; int quotient = a / b; // quotient is 2 double x = 5.5; double y = 2.0; double result = x / y; // result is 2.75
5. Modulus Operator (%)
The modulus operator returns the remainder of the division of the first operand by the second.
int a = 20; int b = 7; int remainder = a % b; // remainder is 6 double x = 5.5; double y = 2.0; double result = x % y; // result is 1.5
Increment and Decrement Operators
While not strictly arithmetic operators, increment and decrement operators are commonly used in arithmetic contexts.
6. Increment Operator (++)
The increment operator increases an integer value by one.
int a = 10; a++; // a is now 11 double x = 5.5; x++; // x is now 6.5
7. Decrement Operator (--)
The decrement operator decreases an integer value by one.
int a = 10; a--; // a is now 9 double x = 5.5; x--; // x is now 4.5
C# is primarily used on the Windows . NET framework, although it can be applied to an open source platform. This highly versatile programming language is an object-oriented programming language (OOP) and comparably new to the game, yet a reliable crowd pleaser.
The C# language is also easy to learn because by learning a small subset of the language you can immediately start to write useful code. More advanced features can be learnt as you become more proficient, but you are not forced to learn them to get up and running. C# is very good at encapsulating complexity.
The decision to opt for C# or Node. js largely hinges on the specific requirements of your project. If you're developing a CPU-intensive, enterprise-level application where stability and comprehensive tooling are crucial, C# might be your best bet.
C# is part of .NET, a free and open source development platform for building apps that run on Windows, macOS, Linux, iOS, and Android. There's an active community answering questions, producing samples, writing tutorials, authoring books, and more.
Copyrights © 2024 letsupdateskills All rights reserved