0

Why this "for statement“ executed without any error?

when " z" did not initialize how it could compare with "x" in "for statement". I think it is possible a garbage value assigned to z when it did not initialize and this compare does not work correctly. https://code.sololearn.com/cqN0BW45C193/?ref=app

28th Mar 2019, 9:26 AM
Alireza Abbasi
Alireza Abbasi - avatar
4 Respuestas
+ 3
Accessing z is undefined behavior, since it wasn't initialized. Different compilers may have different initialization values for that case. The last value which is saved on stack will be returned as first value of z.
28th Mar 2019, 10:24 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
+ 3
Thinking about it, my answer was misleading (aka wrong). Sorry
28th Mar 2019, 11:30 AM
Anna
Anna - avatar
+ 1
You said "then the loop is executed...". I think in " do while() ;" first code execute then survey condition, but in "while and for" first survey condition and after that excute body of them.
28th Mar 2019, 11:22 AM
Alireza Abbasi
Alireza Abbasi - avatar
0
So Can I say this statement is unstable?
28th Mar 2019, 11:43 AM
Alireza Abbasi
Alireza Abbasi - avatar