C
operators are classified into a number of categories. They include:
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and Decrement
operators
6. Conditional operators
7. Bitwise operators
8. Special operators
1.ARITHMETIC
OPERATORS::
The operators are
+ (Addition)
- (Subtraction)
* (Multiplication)
/ (Division)
% (Modulo division)
Eg: 1) a-b 2) a+b 3) a*b 4) p%q
The modulo division produces the
remainder of an integer division.
The modulo division operator
cannot be used on floating point data.
Note: C does not have any operator for exponentiation.
Artthmetic operators are divided into::
a. Integer
Arithmetic
When both the operands in a
single arithmetic expression are integers, the expression
is called an integer
expression , and the operation is called integer arithmetic.
During modulo division the sign
of the result is always the sign of the first operand.
That is
-14 % 3 = -2
-14 % -3 = -2
14 % -3 = 2
b.Real
Arithmetic
An arithmetic operation
involving only real operands is called real arithmetic. If x and y
are floats then we will have:
1) x = 6.0 / 7.0 = 0.857143
2) y = 1.0 / 3.0 = 0.333333
The operator % cannot be used
with real operands.
c.Mixed-mode
Arithmetic
When one of the operands is real
and the other is integer, the expression is called a
mixed-mode
arithmetic expression
and its result is always a real number.
Eg: 1) 15 / 10.0 = 1.5
2.RELATIONAL OPERATORS
1) < (is less than)
2) <= (is less than or equal
to)
3)> (is greater than)
4) >= (is greater than or
equal to)
5) = = (is equal to)
6) != (is not equal to)
3.LOGICAL
OPERATORS
C has the following three logical
operators.
&& (logical AND)
|| (logical OR)
! (logical NOT)
Eg: 1) if(age>55 &&
sal<1000)
2) if(number<0 || number>100)
4.ASSIGNMENT
OPERATORS
The usual assignment operator is
‘=’.In addition, C has a set of ‘shorthand’
assignment operators of the
form, v op = exp;
Eg:1.x += y+1;
This is same as the statement
x=x+(y+1);
Statement with shorthand operator Statement with simple
assignment operator
a + =1 a = a + 1
a - = 1
a = a – 1
a *= n + 1
a = a * (n+1)
a /= n + 1
a = a / (n+1)
a %= b a
= a % b
5.INCREMENT AND
DECREMENT OPERATORS
C has two very useful operators
that are not generally found in other languages. These
are the increment and decrement
operator:
++ and --
The operator ++ adds 1 to the
operands while – subtracts 1.It takes the following
form:
++m; or m++
--m; or m—
6.CONDITIONAL
OPERATOR
A ternary operator pair “?:” is
available in C to construct conditional expression of the
form:
exp1 ? exp2 : exp3;
Here exp1 is evaluated
first. If it is true then the expression exp2 is evaluated and
becomes the value of the
expression. If exp1 is false then exp3 is evaluated and its value
becomes the value of the
expression.
Eg:1) if(a>b)
x = a;
else
x = b;
7. BITWISE
OPERATORS
Operator Meaning
&
Bitwise AND
|
Bitwise OR
^
Bitwise XOR
<< Shift left
>> Shift
right
~
One’s complement
8. SPECIAL
OPERATORS
C supports some special
operators such as
Ø Comma operator
Ø Size of operator
Ø Pointer
operators(& and *) and
Ø Member selection
operators(. and ->)
MATHEMATICAL
FUNCTIONS
Mathematical functions such as
sqrt, cos, log etc., are the most frequently used ones.
To use the mathematical
functions in a C program, we should include the line
#include<math.h>
in the beginning of the program.
Trignometric Function
Meaning
acos(x) Arc cosine of x
asin(x)
Arc sine of x
atan(x) Arc tangent of x
atan2(x,y) Arc tangent of x/y
cos(x) cosine
of x
sin(x)
sine of x
tan(x)
tangent of x
Hyperbolic
cosh(x) Hyperbolic
cosine of x
sinh(x) yperbolic sine of x
tanh(x) Hyperbolic tangent of x
No comments:
Post a Comment
Please comment bellow. Share your knowledge