Chapter 14 - Worked Exercises 1
Exercise 1 - Preprocessor & Compiler
What is the preprocessor?
How are preprocessor directives declared/defined?
Is the following statement true? Macros can be defined to compute certain values at compile time.
What is the effect of an
#includestatement?
Exercise 2 - Macros
What is the syntax for declaring a macro constant? Show an example of declaring a macro constant, and using it in a program.
List 2 issues that come with using macro constants.
What is the preferred method of defining/declaring program-wide constants?
Exercise 3 - Preprocessor Output
Study each of the code snippets below, and write the preprocessor output of the following programs:
#define VALUE_X 10
#define VALUE_Y 20
int main() {
int a = VALUE_X;
int b = VALUE_Y;
int c = a + b;
}#ifndef TEST
#define VALUE_X 10
#define VALUE_Y 20
#else
#define VALUE_X 100
#define VALUE_Y 200
#endif
int main() {
int a = VALUE_X;
int b = VALUE_Y;
int c = a + b;
}#define TEST
#ifndef TEST
#define VALUE_X 10
#define VALUE_Y 20
#else
#define VALUE_X 100
#define VALUE_Y 200
#endif
int main() {
int a = VALUE_X;
int b = VALUE_Y;
int c = a + b;
}Last updated
Was this helpful?