I used the following codes using ideone.com :
#include <stdio.h>
int main(void)
{
int i,j=0;
if(j)
{
j=0;
i=1;
}
printf("%d\n",i);
}
Output: Garbage Value:
#include <stdio.h>
int main(void)
{
int i;
if(0)
{
i=1;
}
printf("%d\n",i);
}
Conclusion:
Error: using a unified local variable I.
Is this because the compiler completely removes the if (0) block during optimization? And such an optimization cannot be performed in the case of if (j), since this is a variable? Will the j value be present at compile time and should the same optimization be done? Or is it that memory is allocated only at runtime?
source
share