|
|
 |
|
|
|
|
DOS_VERSION;
10: cout << and WINDOWS_VERSION\n;
11: #ifdef DemoVersion
12: cout << DemoVersion defined.\n;
13: #else
14: cout << DemoVersion not defined.\n;
15: #endif
16:
17: #ifndef DOS_VERSION
18: cout << DOS_VERSION not defined!\n;
19: #else
20: cout << DOS_VERSION defined as: << DOS_VERSION << endl;
21: #endif
22:
23: #ifdef WINDOWS_VERSION
24: cout << WINDOWS_VERSION defined!\n;
25: #else
26: cout << WINDOWS_VERSION was not defined.\n;
27: #endif
28:
29: cout << Done.\n;
30: return 0;
31: } |
|
|
|
|
|
|
|
|
Output:Checking on the definitions of DemoVersion, DOS_VERSION and WINDOWS_VERSION
DemoVersion defined
DOS_VERSION defined as: 5
WINDOWS_VERSION was not defined.
Done. |
|
|
|
|
|
|
|
|
Analysis: On lines 1 and 2, DemoVersion and DOS_VERSION are defined, with DOS_VERSION defined with the string 5. On line 11, the definition of DemoVersion is tested, and because DemoVersion is defined, albeit with no value, the test is true and the string on line 12 is printed. |
|
|
|
|
|
|
|
|
Line 17 tests DOS_VERSION to see if it is not defined. |
|
|
|
|
|
|
|
|
Because DOS_VERSION is defined, this test fails and execution jumps to line 20. Here the string 5 is substituted for the word DOS_VERSION, and this is seen by the compiler as |
|
|
|
|
|
|
|
|
cout << DOS_VERSION defined as: << 5 << endl; |
|
|
|
|
|
|
|
|
Note that the first word, DOS_VERSION, is not substituted because it is in a quoted string. The second DOS_VERSION is substituted. This causes the compiler to see 5, as if you had typed 5 there. |
|
|
|
|
|