As suggested by
Suvendu Shekhar Giri, you are using the assignment operator instead of the test for equality. Now in
C
programming language, the construct
i=40
is an expression, whoose evaluation is
40
. So writing
if (i=40)
ends up in
if (40)
That is a
true
condition in the
if
(any number but
0
is assumed to be
true
)
That's the reason you're getting such unexpected output.