Page 165 - Computer science 868 Class 12
P. 165

The output of the preceding program is as follows:

















                 What is the difference between left-hand side and right-hand side of the assignment operator?
                 The ‘lvalue’ refers to the operand on the left-hand side of the assignment operator while the ‘rvalue’ refers to the
                 operand on the right-hand side of the assignment operator. The lvalue can be a variable or a pointer but it should not
                 be a constant.

                 6.5.7 Categories of Operators
                 Apart from the above-mentioned six types of operators, there are some other types of operators which are as follows:
                 1.  Unary Operator: This operator contains only one operand.
                   For example: a++, --b

                   [where a and b are the operands; and ++ and -- are the operators]
                 2.  Binary Operator: This operator contains two operands.
                   For example: a + b, a / b
                   [where a and b are the operands; and + and / are the operators]
                 3.  Ternary Operator: This operator contains three operands or expressions. This operator is also known as conditional
                   assignment operator or conditional operator.
                   For example: (a > b) ? a : b
                   [where a and b are the operands; and ? and : are the operators]

                 We have already discussed binary operators such as arithmetic, logical, relational, etc. Let us now discuss unary and
                 ternary operators in detail.


                 Unary Operators
                 Unary operators work on the single operand, i.e., there will be one operand and one operator. For example, +, -, ++, --.
                 They are further of different types as given below.
                 •  Unary (+) Operator: This operator is used to apply before the operand. It results in the same value as the operand.

                   For example: If a = 5, then +a = 5
                                If a = -5, then +a = -5
                 •  Unary (-) Operator: This operator is used to apply before the operand. It results in the opposite value of that of the
                   operand.
                   For example: If a = 5, then -a = -5
                                If a = -5, then -a = 5
                 •  Unary (++) Operator: This operator increases the value of the variable by 1. It is also known as the increment
                   operator.
                   For example: If a =5, then ++a = 6



                                                                                                                       163
                                                                                               Variables and Expressions   163
   160   161   162   163   164   165   166   167   168   169   170