Muthu karthikeyan, Madurai
Operators:
Types of operator:
Arithmetic operator
Short hand assignment operator
Increment /decrement operator
Relational operators
Logic operator
Ternary operator
Arithmetic operator:
+, -, *, /, %
Plus, minus, multiplication, division
First three are same as
mathmetical operations.
Fourth division operation is
different. i.e if we divide a int by another int result is integer only
For example
13/5=2 is the result. Decimal
portions were removed
If at least any one is float or
double the result is float
For example:
13.0/5=2.6
13/5.0=2.6
13.0/5.0=2.6
o.k then what about %
operator? do you think that it is percentage calculating operator?
No
It is called as modulus
operator.
That is one integer is divided
by another integer .it returns remainder value
Example : 13/5=3.
In c , c++ modulus operations are performed on Integer type only.
In advanced languages like java, c sharp,vb.net modulus operator is also can be
used also on float and double.
Short hand Assignment operator:
a=a+5 can be also written as
a+=5
a=a-5 can be also written as
a-=5
It totally applied for all 5
types of arithmetic operator.
Increment/decrement operator:
++,--
a=10;
a++;
now a value will be eleven because
++ operator increases the value by one
also ++a will increment the
values by one.
Next:
--
It is called as decrement
operator.
a=10;
a--;
now q value be only nine. because
decrement operator wil decrement by . one
and --a
may also decrement the value by one.
But in order of execution ++a(pre
increment operator )has order of process high in a mathematical expression is
high. but a++ (post decrement operator).has low precedence. It also applies to decrement
operator.
Relational operator:
It is used for comparing one
value with other value. it returns only true or false value
< less
than
<=less than or equal to
> greater than
>=greater than or equal to
==equals to(note there are
two = symbols
!=not equal to
Examples:
a=10;
b=5;
c=15;
d=10;
a>b ----true
a>c-----false
a==d—true
a!=d---false
logical operators:
compare two or more
relational expression. It also returns true or false value
&&,||,!
&&---(and) both side of relational
expression must be true.
||-(or)at least one side of
expression must be true.
!-it inverts the results (if
the result is true then the result is
false and vice-versa
Examples:
(a>b)&&(a>c)
(a>b)||(a>c)
!(a>b)
Ternary operator:
Make a relational expression execution . if the expression returns
true a value will be returned , if the result is false b value will be returned.
Syntax:
(a>b)?a : b;
a=10;b=5;
big=(a>b)?a:b;
First the comparison(a>b)
returns true so a value(i.e 10) will be returned to big.
contact: 91 96293 29142
No comments:
Post a Comment