@himanshu: preprocessor is a program which is called by the compiler before the actual compilation. see, for the preprocessor directive #if there is a condition that it should be followed by a constant because it is evaluated before compiling the program. Now these constants can be constant say 1,8, etc or it should be define using another preprocessor directive #define.
In ur program, #if i==0, the preprocessor first sees if i here is defined using #define because its not a constant. Since u haven't, it takes the by default value for constant i as 0. This "i" is not ur int i, but it is seen as a #define stuff. see this program for example #include<stdio.h> #include<stdlib.h> #define p 1 int main() { #if i==1 printf("doom"); #endif int i=1; #if j==0 printf("1234"); #endif #if k==5 printf("chaffeur"); #endif #if p==1 printf("srikant"); #endif return 0; } it prints: 1234 and srikant. the statement int i=1 has no role in preprocessing. I have not defined j or k which is used by #if so it will take it as value 0 and checks for the condition which evaluates to true and false respectively. whereas i have defined constant p as 1 using #define, so this condition will evaluate to true printing srikant. In case u want to see the output just after preprocessor runs i.e. before compilation use gcc -E filename. Hope this clears ur doubt. Regards Doom On Jul 2, 12:08 am, himanshu kansal <himanshukansal...@gmail.com> wrote: > If i do #if i==0 thn it vl cmpl it..means its tkng it as 0..bt why... > > On 7/1/11, Dumanshu <duman...@gmail.com> wrote: > > > > > > > > > > > i think it will take a garbage value for i because these are > > preprocessor directives. > > > On Jun 30, 4:46 pm, himanshu kansal <himanshukansal...@gmail.com> > > wrote: > >> 1 more thng....if its possible to eval. variable expression lyk abv... > >> thn... > >> int i=2; > >> #if i==2 > >> printf("hi"); > >> #else > >> printf(""bye); //prints bye....i think it shld print hi... > >> #endif > > >> even this code prints bye..... > > >> int i=3; > >> #if i==2 > >> printf("hi"); > >> #else > >> printf(""bye); > >> #endif > > >> On Thu, Jun 30, 2011 at 5:13 PM, himanshu kansal < > > >> himanshukansal...@gmail.com> wrote: > >> > somewhere i read dt conditional compilation such as #if and #elif etc > >> > cn only use constant expressions and previously defined macros....they > >> > cant use variables cz preprocessng is done b4 compilation... > >> > bt whn i try it on gcc and vc both r compiling it with variables abs. > >> > fyn....even disabling extensions dint work.... > >> > i.e int i; > >> > #if i+1 > >> > printf("hi"); vl print hi...no error occurs > >> > #endif > > >> > thn i read it on net dt it cn eval. varables also.... > >> > nw m confused who is ryt... > >> > whtr it cn eval var also or nt... > >> > nd if it cn thn hws it possible dt preprocessor knows d val. of var. > >> > b4 compiling d prog....... > > >> -- > > >> Regards > >> Himanshu Kansal > >> Msc Comp. sc. > >> (University of Delhi) > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. > > -- > Sent from my mobile device > > Regards > Himanshu Kansal > Msc Comp. sc. > (University of Delhi) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.