I have a problem understanding the output of the code. Any explanation please...
#include<stdio.h>
void main()
{
int x=2,y=5;
x*=y+1;
printf("%d",x);
}
The output is as 12. But as per my understanding x*=y+1;
is x=x*y+1;
but as per operator precedence x*y
should be evaluated followed by adding 1
so it should be 10+1=11. But it is 12 — can anyone explain please?
int main(void)
, notvoid main()
. – Keith Thompson Aug 1 '14 at 6:06printf()
, that's probably where it is being run. Yes, it should beint main(void)
, but MS does allowvoid main()
. – Jonathan Leffler Aug 1 '14 at 6:07