About GBdirect Consultancy Training Development

Section navigation

Leeds Office (National HQ)

GBdirect Ltd
Leeds Innovation Centre
103 Clarendon Road
LEEDS
LS2 9DF
West Yorkshire
United Kingdom

consulting@gbdirect.co.uk

tel: +44 (0)870 200 7273
Sales: 0800 651 0338

South East Regional Office

GBdirect Ltd
18 Lynn Rd
ELY
CB6 1DA
Cambridgeshire
United Kingdom

consulting@gbdirect.co.uk

tel: +44 (0)870 200 7273
Sales: 0800 651 0338

Please note: Initial enquiries should always be directed to our UK national office in Leeds (West Yorkshire), even if the enquiry concerns services delivered in London or South/East England. Clients in London and the South East will typically be handled by staff working in the London or Cambridge areas.

7.5. Exercises

These exercises are intended to test only a basic understanding of the preprocessor, suitable for a beginner. Many users will never need a more detailed understanding.

Exercise 7.1. How would you arrange that the identifier MAXLEN is replaced by the value 100 throughout a program?

Exercise 7.2. What is likely to cause problems in a definition of the form #define VALUE 100+MAXLEN?

Exercise 7.3. Write a macro called REM which takes two integer arguments and ‘returns’ the remainder when the first is divided by the second.

Exercise 7.4. Repeat the last example, but use casts so that any arithmetic type of argument may be used, assuming that there are no overflow problems.

Exercise 7.5. What do the <> brackets around a filename in a #include directive signify?

Exercise 7.6. What would "" mean in place of the <>?

Exercise 7.7. How would you use the preprocessor to select implementation-specific fragments of a program?

Exercise 7.8. What sort of arithmetic does the preprocessor use?