#define tells the preprocessor, “Whenever you encounter A, replace it with B before the compiler sees it.” Look at the line from math.h again:
#define M_PI 3.14159265358979323846264338327950288
In the #define directive, you just separate the two parts (the token and its replacement) with whitespace.
#define can actually be used to make something like a function. In main.m, print the larger of two numbers:
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { NSLog(@"u03c0 is %f", M_PI); NSLog(@"%d is larger", MAX(10, 12)); } return 0; }
MAX is not a function; it is a #define. The most basic C version of MAX is:
#define MAX(A,B) ((A) > (B) ? (A) : (B))
So, by the time the compiler saw the line you just added, it looked like this:
NSLog(@"%d is larger", ((10) > (12) ? (10) : (12)));
When you use #define to do function-like stuff instead of simply substituting a value,you are creating a macro.