in #define lower 0 lower is not a variable. At compile time, lower will be replaced with 0 , where it is used throughout the code.
whereas static int lower = 0; defines a variable, and the actual memory reference will be executed at run time to access the value of the variable. Plus, this value can be changed in your code.
to avoid changes, you can define it like this: static final int lower = 0;
Now compilers do a very good job in optimizing. Therefore, during compilation, this lower will be replaced with 0 .
So, you can only “say” that #define lower 0 in C is equivalent to static final int lower = 0; But they do not match. Because the later one was replaced during the optimization phase. If optimization is disabled, it will not be replaced at compile time.
Hope this helps.
Dhaval
source share