defines a macrodefines a macro with the given


Defines a macro

Defines a macro with the given name, having as its value the given replacement text. After that (for the rest of the current source file), wherever the preprocessor sees that name, it will replace it with the replacement text. The name follows the same rules as ordinary identifiers (it can contain only letters, digits, and underscores, and may not begin with a digit). Since macros behave quite differently from normal variables (or functions), it is customary to give them names which are all capital letters (or at least which begin with a capital letter). The replacement text can be absolutely anything--it's not restricted to numbers, or simple strings, or anything.

The most common use for macros is to propagate various constants around and to make them more self-documenting. We've been saying things like

char line[100];

...

getline(line, 100);

but this is neither readable nor reliable; it's not necessarily obvious what all those 100's scattered around the program are, and if we ever decide that 100 is too small for the size of the array to hold lines, we'll have to remember to change the number in two (or more) places.

A much better solution is to use a macro:

#define MAXLINE 100 char line[MAXLINE];

...

getline(line, MAXLINE);

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: defines a macrodefines a macro with the given
Reference No:- TGS0305457

Expected delivery within 24 Hours