What is the use of #if and #endif directives. In what way it differs from if() { } Thanks
#if is processed by the preprocessor, before the compiler seens any C or C++ code.
A normal if() is seen by the compiler and will be added to your program - the if() will be tested when the program is run.
This means that code skipped by #if will not take any space. You can use it to create conditional builds - for example for two almost identical hardware, where one hardware have extra components mounted (and possibly an extra-large flash for the code needed to control the extra electronics).
This is standard C knowledge, so any good book about C should give you more information.
in short #if .. control what code is compiled if ... controls which code is executed
Erik