Arithmetic Operators and Expressions
C language offers many types of operators. They are,
|
Types
of Operators |
Description |
|
Arithmetic_operators |
These are used to perform mathematical calculations
like addition, subtraction, multiplication, division and modulus |
|
Assignment_operators |
These are used to assign the values for the variables
in C programs. |
|
Relational operators |
These operators are used to compare the value of two
variables. |
|
Logical operators |
These operators are used to perform logical operations on
the given two variables. |
|
Bit wise operators |
These operators are used to perform bit operations on
given two variables. |
|
Conditional (ternary) operators |
Conditional operators return one value if condition is
true and returns another value is condition is false. |
|
Increment/decrement operators |
These operators are used to either increase or decrease
the value of the variable by one. |
|
Special operators |
&, *, sizeof( ) and ternary operators. |
Simple Assignment Statement,
C provides an
assignment operator for this purpose, assigning the value to a variable using
assignment operator is known as an assignment statement in C.
The function of this
operator is to assign the values or values in variables on right hand side of
an expression to variables on the left hand side.
The syntax of the
assignment expression
Variable = constant / variable/ expression;
The data type of the
variable on left hand side should match the data type of
constant/variable/expression on right hand side with a few exceptions where
automatic type conversions are possible.
Examples of assignment statements,
b = c ; /* b is assigned the value
of c */
a = 9 ; /* a is assigned the value
9*/
b = c+5; /* b is assigned the value of expr c+5 */
The expression on the
right hand side of the assignment statement can be:
An arithmetic expression;
A relational expression;
A logical expression;
A mixed expression.
For example,
int a;
float b,c ,avg, t;
avg = (b+c) / 2; /*arithmetic expression */
a = b && c; /*logical expression*/
a = (b+c) && (b<c); /* mixed expression*/