Anda di halaman 1dari 13

Assignment Operators

SEE WITH C
www.swapnamithra.com
Assignment operators
It is a binary operator which requires operands.

When we are working with binary operator if any one of the
argument is missing then it gives an error
When we are working with assignment operators left side argument
must be variable type only and right side argument is a variable
type or constant type
Syntax:- L=R ; L must be variable type
; indicates the end of the statement
(if we dont keep the semicolon(;) we get error in
compilation)




input return value
a=10 error statement missing (;)
a=10; 10
a=13.8; 13.8
a=D; D
a= ; error R value required
=10; error L value required
10=30; error in L value(should be variable)
b=a; a (R can be of any type)

Arithmetic operators
To perform the basic mathematical operations we need to go for
arithmetic operators
Arithmetic operators are of 2 types
1.Unary operators
++,--
2.Binary operators
+,-,*,/,%
We shall discuss about unary operators later
Binary operators
When we are working with this operator we must
require 2 arguments
In implementation when we are evaluating the
expression if the expression contain multiple
operations,inorder to evaluate the exression we need to
follow the priority
Operator with high priority should be evaluated first
Operator with less priority should be evaluated last
When equal priority occur,evaluation should be done
from left to right .if it is unary right to left
Priority order
1. *,/,%
2. +,-
3. =
a=3+5; 8
a=5-3+4; 2+4; 6 (equal priority left to right)
a=4+3*4+3; 4+12+4;16+4;20
a=2*3+2*3; 6+2*3;6+6;12
a=8+ ;error one more argument required
a=5- ;error one more argument required

a=+8; 8
a=-5; -5
When we are working with +,- they work as both unary and binary operands
When the symbol is available before the first argument it is unary and it
indicates the sign of value.
When it is after the first argument it indicates the binary arithmetic operator.
Important note
Operator behaviour doesnt depend on variable type
i.e;according to variable type no need to evaluate the
expression
Always operator behaviour is operand dependent only
i.e;according to input values behaviour the return value
changes
Behaviour of arguments return value
Integer ,integer integer
Integer ,float float
Float ,integer float
Float,float float
operation return value
a=5/2; 2
a=5.0/2; 2.5
a=5/2.0; 2.5
a=5.0/2.0;2.5
a=2/5; 0
a=2.0/5; 0.4
a=5/2.0; 0.4
In division when numerator is less than the denominator value
then return value is zero if both numerator and denominator are integers





Operation return value
a=5/2; 2
a=-5/2; -2
a=5/-2; -2
a=-5/-2; 2
In division operator return value sign will depends on both
numerator,denominator value sign also i.e; if any of the argument
is ve then return value is ve.If both are negative or positive
then return value is +ve

Modulus operator(%)
This operator return the value of remainder after the division of 2arguments
When we are working with modulus operator it require 2 arguments and
they should be of integer type
The return value sign always depends only on numerator sign value
In modulus operator when the numerator value is less than the denominator
value then it retuns the numerator value only

Operation return value
a= 38%5; 3
a=14%2; 0
a=1%7; 1
a=48%5; 3
a=48%-5; 3
a=-48%5; -3
a=-48%-5; -3
a=15.0*5/3%2;
75.0/3%2;
25.0%2; error (% works on integers only)

In implementation if we want to calculate the float data type
then go for fmod(); , fmod1();
These are available in <math.h> header file
Syntax:- value =fmod(n,d); returns double float type
value=fmod1(n,d); returns long double float type
where n is numerator and d is denominator
a=158%10; 8 a=158/10; 15
a=3%10; 3 a=3/10; 0
%10 always provides the last digit of the value and /10
always remove the last digit from the value

Anda mungkin juga menyukai