tell me the output of the following c program and the reason behind it
main()
{
int a=400;
int b;
b=a*a/a;
printf("%d",b);
}
hi there,
in precedence of operators when writing complex expressions with several operands, we may have some doubts about which operand is evaluated first and which later. in your expression
b = a*a/a
we may doubt if it really means:
a = (400*400)/400 // with a result of 400, or a = 400 *(400/400) // with a result of 400 , although you can get the same result this is very critical, what if the values are changed?
The correct answer is the first of the two expressions, with a result of 400. There is an established order with the priority of each operator, and not only the arithmetic ones (those whose preference come from mathematics) but for all the operators which can appear in C++. From greatest to lowest priority,in reading data it always finds the which always comes first.
ok
regards,
mike