associativity - Please explain the output of this simple C program -
this question has answer here:
- trouble float on c [duplicate] 1 answer
- what behavior of integer division? 5 answers
int = 2, j = 3, k, l ; float a, b ; k = / j * j ; l = j / * ; = / j * j ; b = j / * ; printf( "%d %d %f %f", k, l, a, b ) ; }
it simple c program yashwant kanetkar not relate answer . if compile program output getting
0 2 0.00000 2.00000
this simple program not able explain output may getting confused associativity. both / , * have l r associativity , / has unambiguous left operand (necessary condition l r associativity) performed earlier. answer different in case .
it simple associativity of operators, nothing complex.
i think it's "integer division" property making confused.
k = / j * j ;
answer 0, because of integer division first (i / j
== 0).l = j / * ;
answer 2, because of integer division first. (j / i
== 1)a = / j * j ;
answer 0, (promotedfloat
) because of integer division first, mentioned earlier.b = j / * ;
, answer 2, (promotedfloat
) because of integer division first, alo mentioned earlier.
note: a gentle version of mr. haccks said : please avoid referring particular book.
Comments
Post a Comment