||Here are groups of one or more macros followed by a source code line that uses them. What code results in each case? Is it valid code? (Assume C variables have been declared.)|
#define FPM 5280 /* feet per mile */
dist = FPM * miles;
#define FEET 4
#define POD FEET + FEET
plort = FEET * POD;
#define SIX = 6;
nex = SIX;
#define NEW(X) X + 5
y = NEW(y);
berg = NEW(berg) * lob;
est = NEW(berg) / NEW(y);
nilp = lob * NEW(-berg);
dist = 5280 * miles; is valid.
plort = 4 * 4 + 4; is valid. But if the user really wanted 4 * (4 + 4), he or she should have used #define POD (FEET + FEET).
nex = = 6;; is valid, but not meaningful. Apparently, the user forgot that he or she was writing for the preprocessor, not writing in C.
Get C Primer Plus, Fourth Edition now with O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.