Monday, October 26, 2009

Precedence of operators

#include< stdio.h >
main()
{
int i ;
i = 1;
i= i+2*i++;
printf("i is now %d",i);
return;
}

output:
4


How it works?

This operation is performed as per the precedence rules(BODMAS- Bracket of
Division Multiplication Addition Subtraction). As per the BODMAS
the multiplication(*) has higher precedence then the addition(+) so first
Multiplication will be performed after that only the increment and addition
operation is performed.

0 comments:

Post a Comment