Arithmetic Operators
Arithmetic Operators (+, -, *, /, %, post-increment, pre-increment, post-decrement, pre-decrement)
Relational Operators (==, !=, >, <, >= & <=) Logical Operators (&&, || and !)
Bitwise Operators (&, |, ^, ~, >> and <<)
Assignment Operators (=, +=, -=, *=, etc)
Other Operators (conditional, comma, sizeof, address, redirecton)
- Addition: The ‘+’ operator adds two operands. For example, x+y.
- Subtraction: The ‘-‘ operator subtracts two operands. For example, x-y.
- Multiplication: The ‘*’ operator multiplies two operands. For example, x*y.
- Division: The ‘/’ operator divides the first operand by the second. For example, x/y.
- Modulus: The ‘%’ operator returns the remainder when first operand is divided by the second. For example, x%y.
Example program
// C program to demonstrate working of binary arithmetic operators
#include <stdio.h>
int main()
{
int a = 10, b = 4, res;
// printing a and b
printf("a is %d and b is %d\n", a, b);
res = a + b; // addition
printf("a+b is %d\n", res);
res = a - b; // subtraction
printf("a-b is %d\n", res);
res = a * b; // multiplication
printf("a*b is %d\n", res);
res = a / b; // division
printf("a/b is %d\n", res);
res = a % b; // modulus
printf("a%b is %d\n", res);
return 0;
}
a is 10 and b is: 4 a+b is: 14 a-b is: 6 a*b is: 40 a/b is: 2 a%b is: 2
No comments:
Post a Comment