Operation
Operators are the symbols that are used to perform operation. C provides a variety of operators to perform specific mathematical or logical functions.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment operator
- Increment and Decrement Operators
- Compound Assignment Operators
Arithmetic Operator
Arithmetic operator is a symbol that performs mathematical operation on data such that addition, subtraction, multiplication, division and modulus. All arithmetic operators works with numeric values. Modulus operator works only with integer values it's also called reminder operator.
A type of expression in which only arithmetic operators are used is called arithmetic expression. An arithmetic operation may contain integer and floating point number.
Example:
A +B;
m / n;
x + 100;
Relational Operator
The relational operator are used to specify conditions in program. A relational operator compares two values. Relational operator also called comparison operators and result shows in true or false. Some basic relational operators:
- Greater than operator (>) : it returns true if the value on left side of > is greater then the value on the right side.
- Less than operator(<) : it returns true if the value in left side of < is less than the value on right side.
- Equal to operator (==) : it returns true if the values on both side are equal. Otherwise it returns false.
- Not equal (!=) : its not equal to operator and returns true if the value on the left side of < > is not equal to the value on the right.
Logical Operator
The logical operator are used to evaluate compound conditions. There are three logical operator to perform logical operation.
- AND operator
- OR operator
- NOT operator
AND operator
AND operator is used to evaluate two conditions. If both conditions are true it shows true result. The symbol used for AND operator is &&.
OR operator
OR operator is used to evaluate two conditions. If conditions is true it gives true results and when both conditions are false it gives false result. The symbol used for OR operator is(| |).
NOT operator
NOT operator is used to reverse the result of a condition. it gives true result if the condition is false and when condition is true it shows false result. The symbol used for NOT operator is ( ! ).
Increment and Decrement operator
The increment operator is used to increase the 1 value of the variable. its unary operator and work with single variable. it's denoted by the symbol ++. it cannot increment the value of expressions. Increment operator can be used in two forms:
- Prefix Form
In prefix form, the increment operator is written before the variable. The value of variable is incremented by 1. For example:
++y; or ++x;
- Postfix Form
In postfix form, the increment operator is after the variable. For example:
y++; or x++;
The decrement operator is used to decrement the value of variable by 1. it is also a unary operator and denoted by -- symbol. The decrement operator cannot decrement the value pf constant and expressions. The -- operator work similarly as ++ expect it decreases the value of variable 1.
Decrement operator can be used in two forms:
- Prefix Form
- Postfix Form
In postfix form, the decrement value is written after the variable.
For example : y--;
Compound Assignment operator
An assignment statement that assigns a value to many variables is known as compound assignment statement. The assignment operator = is used in this statement. Compound assignment operator combine assignment operator with arithmetic operator . It is used to perform mathematical operations easily.
Syntax
variable op= expression;
The variable is used to assign a value. Op can be any arithmetic operator and expression can be constant, variable or arithmetic operation. For Example:
The statement
N += 10;
is equivalent to
N = N +10;
No comments:
Post a Comment