Can any one let me know when this will work.
I am not able to understand this line as i think will never get compiled because the condition fails as zero. Can any one help me and throw some light on the above code. When will "hello" will be printed..
You are correct, never.
the #if...#endif is a preprocessor directive. This means that during the compile process, if the #if is true then the code following will be compiled, if false it will not.
It's used to compile special code in special places, or to not compile code that has already been compiled. An example of the first type:
printf("we are debugging the code\n");
debval = 1;
debval = 0;
If the preprocessor value DEBUG is set to TRUE, the printf and debval = 1 will be compiled otherwise debval = 0 will be.
I've used this when I was compiling graphics code for Microsoft and Borland compilers in the same code. They use different functions to do the same tasks like cursor positioning.
The second type can be seen in standard .H files. You'll notice in most of these files code that starts with something like:
. . .
This way if a header file is loaded more than once (which is often the case) the first time it's loaded VALUE is not defined so the code is compiled, the second time VALUE is define, so the code is skipped.
This preprocessor statement is used to "comment out" code
#if 0 // What this code says is: If 0>0
as opposed to:
#if 1 // This code will always compile, as it says: if 1>0