More Advanced Types of Definitions
A definition for a name can include more than a simple constant value. It can include an expression and, as you will see shortly, just about anything else!
The following defines the name TWO_PI
as the product of 2.0
and 3.141592654
:
#define TWO_PI 2.0 * 3.141592654
You can subsequently use this defined name anywhere in a program where the expression 2.0 * 3.141592654
would be valid. So, you could replace the return
statement of the circumference
method from the previous example with the following statement:
return TWO_PI * radius;
Whenever a defined name is encountered in an Objective-C program, everything that appears to the right of the defined name in the #define
statement is ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.