printf("sum = %d", sum);
return 0;
}
Output:
sum = 2
Operators in C
Operators are the foundation of any programming language. Thus the functionality of C language
is incomplete without the use of operators. Operators allow us to perform different kinds of
operations on operands. In C, operators in Can be categorized in following categories:
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)
Arithmetic Operators: These are used to perform arithmetic/mathematical operations on
operands. The binary operators falling in this category are:
o Addition: The ‘+’ operator adds two operands. For example, x+y.
o Subtraction: The ‘-‘ operator subtracts two operands. For example, x-y.
o Multiplication: The ‘*’ operator multiplies two operands. For example, x*y.
o Division: The ‘/’ operator divides the first operand by the second. For example,
x/y.
o Modulus: The ‘%’ operator returns the remainder when first operand is divided
by the second. For example, x%y.
// 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