This is really a good question.
The compiler will completely ignore the words ';for(;0;)'; and will start with the next print statement as if it is not in the ';for'; loop at all.
Since there is no syntax error in this, it will get compiled but since the linker knows that the statement following it cannot be reached, it gives us a warning but when you execute, this line will be completly ignored and the next line will be treated as the next line of code. It will not be treated as a loop at all as it has ignored that part. Please note that the warnings are for programmers information and not for the compiler.
Just try typing ';0;'; alone in a line and use ';step over (F8)'; option. You can see this line will not be executed at all but will get compiled as there is no syntax error.
We can even say it is a kind of bug which the programmer should take care. Also this is not the only thing with C to be taken care, there are lot more to be taken care by the programmer like this one. Hope this clarifies your doubt.In c language 0 Menes false,for(;0;)printf(';hello';); than y its printing hello?
have you tried this statement?
The ';printf'; statement is unreachable.
then how can you have it displayed?
You might have inlcluded ';'(semicolon) after ';for'; statement.
Verify.In c language 0 Menes false,for(;0;)printf(';hello';); than y its printing hello?
try the following
for(;0;) {
printf(';hello';);
}
it is printing anything
I am sure it will not be coz u included ; at the end of for loop
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment