Introduction
The ifelse directive lets us specify the action if the condition is not true.
Program
Suppose we have three files:
file1.h #define USD 1 file2.h #define UKP 1 file3 #include#include //A #if (defined (USD)) // B #define currency_rate 46 #else #define currency_rate 100 //C #endif //D main() { int rs; rs = 10 * currency_rate; //H printf ("%d\n", rs); }
Explanation
-
Statement B indicates the ifelse directive.
-
If the identifier USD is defined, the currency rate is taken as 46; otherwise, the currency rate is taken as 100.
-
Since USD is defined in file1.h, the currency rate is taken as 46.
Point to Remember
The ifelse directive allows us to take action if the condition is not satisfied.
No comments:
Post a Comment