Expression:
Expression is the combination of operators and operands.
4+1 is expression now 2 is operand and + is operator.
Expression is divided in to two parts.
1) Operands:
Operands are of two types constant for example ( 1, 2, 3) and variable for example ( a, b, c)
2) Operators:
Any special symbol or computer program that perform specific task is called operator.
Types of Operators:
1.1) Unary Operator.
2.1) Binary Operator.
3.1) Ternary Operator.
1.1) Unary operator:
Unary operator need a single value for example ( -5, +8) etc.
2.1) Binary operator:
Binary operator need two value for example: ( 7-3, 6/7, 2*8) etc
3.1) Ternary operator:
Ternary operator takes in a boolean value, and two statements and returns the return value of the first statement if the boolean value is true, and the return value of the second statement if the boolean value is false.
for example:
z= (x >y)? x:y assigns x to z if x is greater than y, and otherwise assigns y to z ( the statement sets z equal to the maximum of x and y)
some programmers regard using this ternary operator as a bad practice, though it can be useful in certain circumstance to avoid excessive if statement.
some programmers regard using this ternary operator as a bad practice, though it can be useful in certain circumstance to avoid excessive if statement.
Priority of operators:
Priority mean that in equation what value is first solve.
1) ()
In the equation C solve first those values which are enclosed in the bracket.
2) /, *,%
The priority of these three is same but C solve that operator first which is to the most left side to in the equation.
3) +,-
The priority of these two are same but C solve that one first which is to the most left side in the equation.
4) =
last priority is of = .
We know some sign that for what purpose they are used but %, =, and ( ) we can not know now we can discus one by one .
for example:
5/2 = 2.5 but when we put % sign then the answer is 5/2 = 1 because it show the reminder. It can not be applied on float. on using % the sign of the remainder is always same as the sign of the numerator. thus -5%2 yield -1, where 5/-2 yield 1.
= this sign is used to assign value to variable etc.
for example:
a =67, t = 50 , a+d=u-t etc.
some example are there.
1) i = 2*3/4+4/4+8-2+5/8
step wise solution:
i=2*3/4+4/4+8-2+5/8
= 6/4+4/4+8-2+5/8
= 1+4/4+8-2+5/8
= 1+1+8-2+5/8
= 1+1+8-2+0
= 2+8-2+0
= 10-2+0
= 8+0
i = 8 ans.
In the above equation 6/4 gives 1 and not 1.5 because both are integer values and 5/8 gives 0 because these both are integer value.
No comments:
Post a Comment