Skip to main content

Posts

Showing posts from May 18, 2008

Hierarchy of Operations

The preference in which arithematic operations are performed in an arithematic expression is called as Hierarchy of operations. Its very important in C Programming to predefine the Hierarchy of operations to the C compiler in order to solve the given arithematic expression correctly. e.g.: If a programmer wishes to perform ,z=a+b/c;it may be interpretted as z=(a+b)/c or z=a+(b/c). and if a=3,b=6,c=2 then using the same expression we will obtain two different answwers as z=4.5 or z=6. To avoid this condition we must be aware of hierarchy of operations used in C programming. In arithematic expressions scanning is always done from left to right. The priority of operations is as shown below, Priority Operators First Paranthesis os brackets() Second Multiplication & Divison Third Addition & Substraction Fourth Assignment i.e.= If we consider the logical operators used in C language,the operator precedence will be like; Operators Type ! Logical

Increment-Decrement Operators

PRE/POST INCREMENT/DECREMENT OPERATORS(Unary operators) In programming we often require to increment value of certain variable in step of one or may require to decrement a value. This is usually written as i=i+1 for incrementing the value of variable i or i=i-1 to decrement the value of i. To accomplish this C language provides unary operators called as increment/decrement operators.Using these operators the above variable can be written as i++ or ++i. If ++ is after the variable then it is called as post increment and if it is before the variable then it is called as predecrement. In case of post increment(i++) the old value of the variable is used first and then the increment in the value of variable is done. In preincrement the value of variable is incremented first and then this value is used in the expression. same is in the case of decrement,i.e.pre decremant and post decrement, denoted as --i and i--.