The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
Arithmetic operators can be used to perform arithmetic operations such as Addition, Subtraction, Multiplication and Division. Arithmetic operators are most commonly used operators in computer programming languages. The operands involved in arithmetic operations must represent numerical value. Thus, the operands can be an integer type, floating point types, double and char(In C, characters represent numerical value according to ASCII table). Arithmetic operators can be divided into 3 types, they are
Binary operators are act upon a two operands to produce a new value.
Operator | Description | Example |
---|---|---|
+ | Addition | 1 + 2 = 3 |
- | Subtraction | 2 - 1 = 1 |
* | multiplication | 2 * 3 = 6 |
/ | Division | 6 / 3 = 2 |
% | Modular Division | 5 % 2 = 1 (remainder) |
In this program, we make use of several Binary Operators.
#include <stdio.h> //header file section int main() //main section { int a = 5; int b = 2; int l = a + b; int m = a - b; int n = a * b; int o = a / b; int p = a % b; printf("Addition of a and b = %d ", l); printf("\nSubtraction of a and b = %d ", m); printf("\nMultiplication of a and b = %d ", n); printf("\nDivision of a and b = %d ", o); printf("\nRemainder of a and b = %d ", p); return 0; }
Unary operators are act upon a single operand to produce a new value.
Let we make use of minus Unary operator and have fun
#include <stdio.h> //header file section int main() //main section { int x = -5; int y = -x; printf("The value of x = %d \nThe value of y = %d ",x, y); return 0; }
'-' operator multiplies minus with a value in variable 'x'.
Let we make use of Increment Unary operator and have fun
#include <stdio.h> //header file section int main() //main section { int a = 2; printf("The value of a = %d ", a); a = ++a; printf("\nThe value of a = %d ", a); return 0; }
An increment operator ++ followed by a variable 'a' will be incremented immediately to the value 3.
The vital purpose of increment Unary Operator is to add one to their operand.
Let we make use of Decrement Unary operator and have fun
#include <stdio.h> //header file section int main() //main section { int a = 2; printf("The value of a = %d ",a); a = --a; printf("\nThe value of a = %d ",a); return 0; }
An decrement operator -- followed by a variable 'a' will be decremented immediately to the value 1.
The vital purpose of Decrement Unary operator is to reduce or subtract one to their operand.
Let we make use of Address(&) Unary operator and have fun
#include <stdio.h> //header file section int main() { int n = 10; printf("The value of n = %d ",n); printf("\nAddress of n = %u ",&n); return 0; }
Memory location for a data can be find out with & operator followed by its variable name. Addresses may differs with respect to memory management architecture of an operating system.
While the programmer plays with pointer, the address operator is the one which is most frequenty get used.
Let we make use of sizeof() Unary operator and have fun
#include <stdio.h> int main() { int x = 5; float y = 10; printf("sizeof (x) = %d \nsizeof (y) = %d ",sizeof(x), sizeof(y)); return 0; }
Here, the variables declared and initialized as x and y. The variable x is an integer and y is a float data type. Using sizeof() operator, we can identified the size of the variable.
While the programmer plays with dynamic memory allocation, the sizeof() operator is the one which is most frequenty get used.
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019