| 1. |
Two pairs C++ expressions are given below. 1. a=10, a==10 2. b=a++, b=++a How do they differ? What will be the effect of the expression |
|
Answer» 1. = is an assignment operator that assigns a value 10 to the LHS (Left Hand Side)variable a But == is equality operator that checks whether the LHS and RHS are equal or not. If it is equal it returns a true value otherwise false 2. In a++,++is a post(means after the operand) increment operator and in ++a, ++ is a pre(means before the operand) increment operator. They are entirely different. Post increment: Here first use the value of ‘a’ and then change the value of ‘a’. Eg: if a= 10 then b=a++. After this statement b= 10 and a=11 Pre increment: Here first change the value of a and then use the value of a. Eg: if a=10 then b=++a. After this statement b=11 and a=11. |
|